1

Suppose we have the following command and its related output :

gsettings list-recursively org.gnome.Terminal.ProfilesList | head -n 1 | grep -oP '(?<=\[).*?(?=\])'

Output :

'b1dcc9dd-5262-4d8d-a863-c897e6d979b9', 'ca4b733c-53f2-4a7e-8a47-dce8de182546', '802e8bb8-1b78-4e1b-b97a-538d7e2f9c63', '892cd84f-9718-46ef-be06-eeda0a0550b1', '6a7d836f-b2e8-4a1e-87c9-e64e9692c8a8', '2b9e8848-0b4a-44c7-98c7-3a7e880e9b45', 'b23a4a62-3e25-40ae-844f-00fb1fc244d9'

I need to use gsettings command in a script and create filenames regarding to output ot gessetings command. For example a file name should be

b1dcc9dd-5262-4d8d-a863-c897e6d979b9

the next one :

ca4b733c-53f2-4a7e-8a47-dce8de182546

and so on.

How I can do this?

2 Answers 2

1

Another solution... just pipe the output of your command to:

your_command | sed "s/[ ']//g" | xargs -d, touch
Sign up to request clarification or add additional context in comments.

2 Comments

You can change your sed command to exit early and then OP could get rid of | head -1: sed "s/[ ']//g;1q". To also replace ][ you just need to add it in the front of the character class: sed "s/[][ ']//g;1q" This will let OP pipe gsettings directly to sed.
@dev-null: you're 100% right. Will let OP to change his initial cmd as per your suggestion
0

You can use process substitution to read your gsettings output and store it in an array :

IFS=', ' read -r -a array < <(gsettings)
for f in "${array[@]}"
do
    file=$(echo $f |tr -d "'" ) # removes leading and trailing quotes
    touch "$file"
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.