Using parameter substitution on a Bash array Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionIndexing and modifying Bash parameter array $@Auto-expansion problem with array elements containing an '*' (asterisk)How to do a control loopaccess elements in string array - stray @ symbolDouble quotes in bashUsage of ! in parameter expansionProperly escaping output from command substitution to be used as arguments for another commandHow to add values to an array which contains a variable in the array name in bash?Why is bash history substitution still enabled by default?Unexpected outcome of a=“$@”

Jaya, Venerated Firemage + Chandra's Pyrohelix = 4 damage among two targets?

Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?

Is Diceware more secure than a long passphrase?

As an international instructor, should I openly talk about my accent?

What is the best way to deal with NPC-NPC combat?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

My bank got bought out, am I now going to have to start filing tax returns in a different state?

Is it acceptable to use working hours to read general interest books?

What is /etc/mtab in Linux?

A faster way to compute the largest prime factor

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

How to have a sharp product image?

Could moose/elk survive in the Amazon forest?

What is the difference between Religion and Dharma?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Which big number is bigger?

What makes accurate emulation of old systems a difficult task?

What is purpose of DB Browser(dbbrowser.aspx) under admin tool?

What is the least dense liquid under normal conditions?

What is it called when you ride around on your front wheel?

How would I use different systems of magic when they are capable of the same effects?

Why doesn't the standard consider a template constructor as a copy constructor?

How to open locks without disable device?

What is this word supposed to be?



Using parameter substitution on a Bash array



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionIndexing and modifying Bash parameter array $@Auto-expansion problem with array elements containing an '*' (asterisk)How to do a control loopaccess elements in string array - stray @ symbolDouble quotes in bashUsage of ! in parameter expansionProperly escaping output from command substitution to be used as arguments for another commandHow to add values to an array which contains a variable in the array name in bash?Why is bash history substitution still enabled by default?Unexpected outcome of a=“$@”



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6















I have file.txt that I need to read into a Bash array. Then I need to remove spaces, double quotes and all but the first comma in every entry. Here's how far I've gotten:



$ cat file.txt
10,this
2 0 , i s
30,"all"
40,I
50,n,e,e,d,2
60",s e,e"

$ cat script.sh
#!/bin/bash
readarray -t ARRAY<$1
ARRAY=( "$ARRAY[@]// /" )
ARRAY=( "$ARRAY[@]//"/" )
for ELEMENT in "$ARRAY[@]";do
echo "|ELEMENT|$ELEMENT|"
done

$ ./script.sh file.txt
|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,n,e,e,d,2|
|ELEMENT|60,se,e|


Which works great except for the comma situation. I'm aware that there are multiple ways to skin this cat, but due to the larger script this is a part of, I'd really like to use parameter substitution to get to here:



|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,need2|
|ELEMENT|60,see|


Is this possible via parameter substitution?










share|improve this question

















  • 3





    Is there any reason you need to keep the text in an array, and why you can't let e.g. awk or sed do the processing of the data?

    – Kusalananda
    Mar 26 at 15:49











  • @Jeff -- Looping over the array will be a nightmare to implement in the larger script I'm working on.

    – Jon Red
    Mar 26 at 16:04






  • 3





    @JonRed I don't know what you are doing, so it's entirely possible that you may not have a choice in the matter, but generally, when you find yourself doing such complex string acrobatics in the shell, that's a very good indication that you should be using an actual programming language. The shell is not designed as a programming language, and while it can be used as one, it really isn't a good idea for more complex things. I strongly urge you to consider switching to perl or python or any other scripting language.

    – terdon
    Mar 26 at 16:12











  • @terdon It's funny, I just got done saying almost the exact same thing to my colleague before I read this post. I basically said this is the final version of this script and that any further requirements will necessitate re-writing in Perl. So yeah, I definitely agree

    – Jon Red
    Mar 26 at 17:37

















6















I have file.txt that I need to read into a Bash array. Then I need to remove spaces, double quotes and all but the first comma in every entry. Here's how far I've gotten:



$ cat file.txt
10,this
2 0 , i s
30,"all"
40,I
50,n,e,e,d,2
60",s e,e"

$ cat script.sh
#!/bin/bash
readarray -t ARRAY<$1
ARRAY=( "$ARRAY[@]// /" )
ARRAY=( "$ARRAY[@]//"/" )
for ELEMENT in "$ARRAY[@]";do
echo "|ELEMENT|$ELEMENT|"
done

$ ./script.sh file.txt
|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,n,e,e,d,2|
|ELEMENT|60,se,e|


Which works great except for the comma situation. I'm aware that there are multiple ways to skin this cat, but due to the larger script this is a part of, I'd really like to use parameter substitution to get to here:



|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,need2|
|ELEMENT|60,see|


Is this possible via parameter substitution?










share|improve this question

















  • 3





    Is there any reason you need to keep the text in an array, and why you can't let e.g. awk or sed do the processing of the data?

    – Kusalananda
    Mar 26 at 15:49











  • @Jeff -- Looping over the array will be a nightmare to implement in the larger script I'm working on.

    – Jon Red
    Mar 26 at 16:04






  • 3





    @JonRed I don't know what you are doing, so it's entirely possible that you may not have a choice in the matter, but generally, when you find yourself doing such complex string acrobatics in the shell, that's a very good indication that you should be using an actual programming language. The shell is not designed as a programming language, and while it can be used as one, it really isn't a good idea for more complex things. I strongly urge you to consider switching to perl or python or any other scripting language.

    – terdon
    Mar 26 at 16:12











  • @terdon It's funny, I just got done saying almost the exact same thing to my colleague before I read this post. I basically said this is the final version of this script and that any further requirements will necessitate re-writing in Perl. So yeah, I definitely agree

    – Jon Red
    Mar 26 at 17:37













6












6








6


1






I have file.txt that I need to read into a Bash array. Then I need to remove spaces, double quotes and all but the first comma in every entry. Here's how far I've gotten:



$ cat file.txt
10,this
2 0 , i s
30,"all"
40,I
50,n,e,e,d,2
60",s e,e"

$ cat script.sh
#!/bin/bash
readarray -t ARRAY<$1
ARRAY=( "$ARRAY[@]// /" )
ARRAY=( "$ARRAY[@]//"/" )
for ELEMENT in "$ARRAY[@]";do
echo "|ELEMENT|$ELEMENT|"
done

$ ./script.sh file.txt
|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,n,e,e,d,2|
|ELEMENT|60,se,e|


Which works great except for the comma situation. I'm aware that there are multiple ways to skin this cat, but due to the larger script this is a part of, I'd really like to use parameter substitution to get to here:



|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,need2|
|ELEMENT|60,see|


Is this possible via parameter substitution?










share|improve this question














I have file.txt that I need to read into a Bash array. Then I need to remove spaces, double quotes and all but the first comma in every entry. Here's how far I've gotten:



$ cat file.txt
10,this
2 0 , i s
30,"all"
40,I
50,n,e,e,d,2
60",s e,e"

$ cat script.sh
#!/bin/bash
readarray -t ARRAY<$1
ARRAY=( "$ARRAY[@]// /" )
ARRAY=( "$ARRAY[@]//"/" )
for ELEMENT in "$ARRAY[@]";do
echo "|ELEMENT|$ELEMENT|"
done

$ ./script.sh file.txt
|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,n,e,e,d,2|
|ELEMENT|60,se,e|


Which works great except for the comma situation. I'm aware that there are multiple ways to skin this cat, but due to the larger script this is a part of, I'd really like to use parameter substitution to get to here:



|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,need2|
|ELEMENT|60,see|


Is this possible via parameter substitution?







bash shell-script array variable-substitution parameter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 15:44









Jon RedJon Red

748




748







  • 3





    Is there any reason you need to keep the text in an array, and why you can't let e.g. awk or sed do the processing of the data?

    – Kusalananda
    Mar 26 at 15:49











  • @Jeff -- Looping over the array will be a nightmare to implement in the larger script I'm working on.

    – Jon Red
    Mar 26 at 16:04






  • 3





    @JonRed I don't know what you are doing, so it's entirely possible that you may not have a choice in the matter, but generally, when you find yourself doing such complex string acrobatics in the shell, that's a very good indication that you should be using an actual programming language. The shell is not designed as a programming language, and while it can be used as one, it really isn't a good idea for more complex things. I strongly urge you to consider switching to perl or python or any other scripting language.

    – terdon
    Mar 26 at 16:12











  • @terdon It's funny, I just got done saying almost the exact same thing to my colleague before I read this post. I basically said this is the final version of this script and that any further requirements will necessitate re-writing in Perl. So yeah, I definitely agree

    – Jon Red
    Mar 26 at 17:37












  • 3





    Is there any reason you need to keep the text in an array, and why you can't let e.g. awk or sed do the processing of the data?

    – Kusalananda
    Mar 26 at 15:49











  • @Jeff -- Looping over the array will be a nightmare to implement in the larger script I'm working on.

    – Jon Red
    Mar 26 at 16:04






  • 3





    @JonRed I don't know what you are doing, so it's entirely possible that you may not have a choice in the matter, but generally, when you find yourself doing such complex string acrobatics in the shell, that's a very good indication that you should be using an actual programming language. The shell is not designed as a programming language, and while it can be used as one, it really isn't a good idea for more complex things. I strongly urge you to consider switching to perl or python or any other scripting language.

    – terdon
    Mar 26 at 16:12











  • @terdon It's funny, I just got done saying almost the exact same thing to my colleague before I read this post. I basically said this is the final version of this script and that any further requirements will necessitate re-writing in Perl. So yeah, I definitely agree

    – Jon Red
    Mar 26 at 17:37







3




3





Is there any reason you need to keep the text in an array, and why you can't let e.g. awk or sed do the processing of the data?

– Kusalananda
Mar 26 at 15:49





Is there any reason you need to keep the text in an array, and why you can't let e.g. awk or sed do the processing of the data?

– Kusalananda
Mar 26 at 15:49













@Jeff -- Looping over the array will be a nightmare to implement in the larger script I'm working on.

– Jon Red
Mar 26 at 16:04





@Jeff -- Looping over the array will be a nightmare to implement in the larger script I'm working on.

– Jon Red
Mar 26 at 16:04




3




3





@JonRed I don't know what you are doing, so it's entirely possible that you may not have a choice in the matter, but generally, when you find yourself doing such complex string acrobatics in the shell, that's a very good indication that you should be using an actual programming language. The shell is not designed as a programming language, and while it can be used as one, it really isn't a good idea for more complex things. I strongly urge you to consider switching to perl or python or any other scripting language.

– terdon
Mar 26 at 16:12





@JonRed I don't know what you are doing, so it's entirely possible that you may not have a choice in the matter, but generally, when you find yourself doing such complex string acrobatics in the shell, that's a very good indication that you should be using an actual programming language. The shell is not designed as a programming language, and while it can be used as one, it really isn't a good idea for more complex things. I strongly urge you to consider switching to perl or python or any other scripting language.

– terdon
Mar 26 at 16:12













@terdon It's funny, I just got done saying almost the exact same thing to my colleague before I read this post. I basically said this is the final version of this script and that any further requirements will necessitate re-writing in Perl. So yeah, I definitely agree

– Jon Red
Mar 26 at 17:37





@terdon It's funny, I just got done saying almost the exact same thing to my colleague before I read this post. I basically said this is the final version of this script and that any further requirements will necessitate re-writing in Perl. So yeah, I definitely agree

– Jon Red
Mar 26 at 17:37










5 Answers
5






active

oldest

votes


















9














I would remove what you need to remove using sed before loading into the array (also note the lower case variable names, in general it is best to avoid capitalized variables in shell scripts):



#!/bin/bash
readarray -t array< <(sed 's/"//g; s/ *//g; s/,/"/; s/,//g; s/"/,/' "$1")
for element in "$array[@]";do
echo "|ELEMENT|$element|"
done


This produces the following output on your example file:



$ foo.sh file 
|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,need2|
|ELEMENT|60,see|



If you really must use parameter substitution, try something like this:



#!/bin/bash
readarray -t array< "$1"
array=( "$array[@]// /" )
array=( "$array[@]//"/" )
array=( "$array[@]/,/"" )
array=( "$array[@]//,/" )
array=( "$array[@]/"/," )

for element in "$array[@]"; do
echo "|ELEMENT|$element|"
done





share|improve this answer




















  • 1





    @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

    – terdon
    Mar 26 at 16:06






  • 1





    Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

    – Kusalananda
    Mar 26 at 16:08






  • 1





    @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

    – terdon
    Mar 26 at 16:10











  • Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

    – Jon Red
    Mar 26 at 16:20


















10














As far as I can see, there's no need to read it into a bash array to create that output:



$ sed 's/[ "]//g; s/,/ /; s/,//g; s/ /,/; s/.*/|ELEMENT|&|/' <file
|ELEMENT|10,this|
|ELEMENT|20,is|
|ELEMENT|30,all|
|ELEMENT|40,I|
|ELEMENT|50,need2|
|ELEMENT|60,see|


The sed expression deletes spaces and double quotes, replaces the first comma with a space (there are no other spaces in the string at this point), deletes all other commas, restores the first comma, and the prepends and appends the extra data.



Alternatively, with GNU sed:



sed 's/[ "]//g; s/,//2g; s/.*/|ELEMENT|&|/' <file


(standard sed does not support the combination of 2 and g as flags to the s command).






share|improve this answer




















  • 1





    with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

    – glenn jackman
    Mar 26 at 16:02






  • 2





    And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

    – glenn jackman
    Mar 26 at 16:04






  • 1





    @glennjackman Possibly, but it looks rather neat.

    – Kusalananda
    Mar 26 at 16:05











  • Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

    – Jon Red
    Mar 26 at 16:06











  • If I wasn't tied to using an array, however, this would be best solution.

    – Jon Red
    Mar 26 at 16:24


















9














ELEMENT='50,n,e,e,d,2'
IFS=, read -r first rest <<<"$ELEMENT"
printf "%s,%sn" "$first" "$rest//,/"




50,need2


Get out of the habit of using ALLCAPS variable names. You'll eventually collide with a crucial "system" variable like PATH and break your code.






share|improve this answer























  • Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

    – Jon Red
    Mar 26 at 16:14






  • 1





    I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

    – glenn jackman
    Mar 26 at 16:17






  • 1





    There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

    – Jeff Schaller
    Mar 26 at 16:19


















8














[This is essentially a more fully developed version of glenn jackmann's answer]



Building an associative array from the stripped key and value, using the first comma as separator:



declare -A arr
while IFS=, read -r k v; do arr["$k//[ "]"]="$v//[ ,"]"; done < file.txt
for k in "$!arr[@]"; do
printf '|ELEMENT|%s,%s|n' "$k" "$arr[$k]"
done
|ELEMENT|20,is|
|ELEMENT|10,this|
|ELEMENT|50,need2|
|ELEMENT|40,I|
|ELEMENT|60,see|
|ELEMENT|30,all|





share|improve this answer






























    6














    You could loop over the array and use an intermediate variable:



    for((i=0; i < "$#ARRAY[@]"; i++))
    do
    rest="$ARRAY[i]#*,"
    ARRAY[i]="$ARRAY[i]%%,*","$rest//,/"
    done


    This assigns to rest the portion after the first comma; we then concatenate three pieces back into the original variable:



    • the portion before the first comma

    • a comma

    • the replacement in rest of every comma with nothing





    share|improve this answer























    • This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

      – Jon Red
      Mar 26 at 16:26






    • 1





      Fair enough; I just tried to answer within the limitations (parameter expansion only).

      – Jeff Schaller
      Mar 26 at 16:27











    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508777%2fusing-parameter-substitution-on-a-bash-array%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9














    I would remove what you need to remove using sed before loading into the array (also note the lower case variable names, in general it is best to avoid capitalized variables in shell scripts):



    #!/bin/bash
    readarray -t array< <(sed 's/"//g; s/ *//g; s/,/"/; s/,//g; s/"/,/' "$1")
    for element in "$array[@]";do
    echo "|ELEMENT|$element|"
    done


    This produces the following output on your example file:



    $ foo.sh file 
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|



    If you really must use parameter substitution, try something like this:



    #!/bin/bash
    readarray -t array< "$1"
    array=( "$array[@]// /" )
    array=( "$array[@]//"/" )
    array=( "$array[@]/,/"" )
    array=( "$array[@]//,/" )
    array=( "$array[@]/"/," )

    for element in "$array[@]"; do
    echo "|ELEMENT|$element|"
    done





    share|improve this answer




















    • 1





      @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

      – terdon
      Mar 26 at 16:06






    • 1





      Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

      – Kusalananda
      Mar 26 at 16:08






    • 1





      @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

      – terdon
      Mar 26 at 16:10











    • Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

      – Jon Red
      Mar 26 at 16:20















    9














    I would remove what you need to remove using sed before loading into the array (also note the lower case variable names, in general it is best to avoid capitalized variables in shell scripts):



    #!/bin/bash
    readarray -t array< <(sed 's/"//g; s/ *//g; s/,/"/; s/,//g; s/"/,/' "$1")
    for element in "$array[@]";do
    echo "|ELEMENT|$element|"
    done


    This produces the following output on your example file:



    $ foo.sh file 
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|



    If you really must use parameter substitution, try something like this:



    #!/bin/bash
    readarray -t array< "$1"
    array=( "$array[@]// /" )
    array=( "$array[@]//"/" )
    array=( "$array[@]/,/"" )
    array=( "$array[@]//,/" )
    array=( "$array[@]/"/," )

    for element in "$array[@]"; do
    echo "|ELEMENT|$element|"
    done





    share|improve this answer




















    • 1





      @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

      – terdon
      Mar 26 at 16:06






    • 1





      Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

      – Kusalananda
      Mar 26 at 16:08






    • 1





      @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

      – terdon
      Mar 26 at 16:10











    • Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

      – Jon Red
      Mar 26 at 16:20













    9












    9








    9







    I would remove what you need to remove using sed before loading into the array (also note the lower case variable names, in general it is best to avoid capitalized variables in shell scripts):



    #!/bin/bash
    readarray -t array< <(sed 's/"//g; s/ *//g; s/,/"/; s/,//g; s/"/,/' "$1")
    for element in "$array[@]";do
    echo "|ELEMENT|$element|"
    done


    This produces the following output on your example file:



    $ foo.sh file 
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|



    If you really must use parameter substitution, try something like this:



    #!/bin/bash
    readarray -t array< "$1"
    array=( "$array[@]// /" )
    array=( "$array[@]//"/" )
    array=( "$array[@]/,/"" )
    array=( "$array[@]//,/" )
    array=( "$array[@]/"/," )

    for element in "$array[@]"; do
    echo "|ELEMENT|$element|"
    done





    share|improve this answer















    I would remove what you need to remove using sed before loading into the array (also note the lower case variable names, in general it is best to avoid capitalized variables in shell scripts):



    #!/bin/bash
    readarray -t array< <(sed 's/"//g; s/ *//g; s/,/"/; s/,//g; s/"/,/' "$1")
    for element in "$array[@]";do
    echo "|ELEMENT|$element|"
    done


    This produces the following output on your example file:



    $ foo.sh file 
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|



    If you really must use parameter substitution, try something like this:



    #!/bin/bash
    readarray -t array< "$1"
    array=( "$array[@]// /" )
    array=( "$array[@]//"/" )
    array=( "$array[@]/,/"" )
    array=( "$array[@]//,/" )
    array=( "$array[@]/"/," )

    for element in "$array[@]"; do
    echo "|ELEMENT|$element|"
    done






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 26 at 16:10

























    answered Mar 26 at 15:52









    terdonterdon

    135k33271450




    135k33271450







    • 1





      @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

      – terdon
      Mar 26 at 16:06






    • 1





      Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

      – Kusalananda
      Mar 26 at 16:08






    • 1





      @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

      – terdon
      Mar 26 at 16:10











    • Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

      – Jon Red
      Mar 26 at 16:20












    • 1





      @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

      – terdon
      Mar 26 at 16:06






    • 1





      Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

      – Kusalananda
      Mar 26 at 16:08






    • 1





      @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

      – terdon
      Mar 26 at 16:10











    • Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

      – Jon Red
      Mar 26 at 16:20







    1




    1





    @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

    – terdon
    Mar 26 at 16:06





    @JonRed I added a version with parameter substitution but it's complex, cumbersome and ugly. Doing this sort of thing in the shell is very rarely a good idea.

    – terdon
    Mar 26 at 16:06




    1




    1





    Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

    – Kusalananda
    Mar 26 at 16:08





    Note that if you've removed both spaces and double quotes, these characters becoma available to use instead of your RANDOMTEXTTHATWILLNEVERBEINTHEFILE.

    – Kusalananda
    Mar 26 at 16:08




    1




    1





    @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

    – terdon
    Mar 26 at 16:10





    @Kusalananda yeah, I just read your answer. Should have thought of that! Thanks :)

    – terdon
    Mar 26 at 16:10













    Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

    – Jon Red
    Mar 26 at 16:20





    Directly answers the question, illustrates why my preferred solution isn't ideal, and provides the most viable alternative. You win, best answer.

    – Jon Red
    Mar 26 at 16:20













    10














    As far as I can see, there's no need to read it into a bash array to create that output:



    $ sed 's/[ "]//g; s/,/ /; s/,//g; s/ /,/; s/.*/|ELEMENT|&|/' <file
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|


    The sed expression deletes spaces and double quotes, replaces the first comma with a space (there are no other spaces in the string at this point), deletes all other commas, restores the first comma, and the prepends and appends the extra data.



    Alternatively, with GNU sed:



    sed 's/[ "]//g; s/,//2g; s/.*/|ELEMENT|&|/' <file


    (standard sed does not support the combination of 2 and g as flags to the s command).






    share|improve this answer




















    • 1





      with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

      – glenn jackman
      Mar 26 at 16:02






    • 2





      And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

      – glenn jackman
      Mar 26 at 16:04






    • 1





      @glennjackman Possibly, but it looks rather neat.

      – Kusalananda
      Mar 26 at 16:05











    • Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

      – Jon Red
      Mar 26 at 16:06











    • If I wasn't tied to using an array, however, this would be best solution.

      – Jon Red
      Mar 26 at 16:24















    10














    As far as I can see, there's no need to read it into a bash array to create that output:



    $ sed 's/[ "]//g; s/,/ /; s/,//g; s/ /,/; s/.*/|ELEMENT|&|/' <file
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|


    The sed expression deletes spaces and double quotes, replaces the first comma with a space (there are no other spaces in the string at this point), deletes all other commas, restores the first comma, and the prepends and appends the extra data.



    Alternatively, with GNU sed:



    sed 's/[ "]//g; s/,//2g; s/.*/|ELEMENT|&|/' <file


    (standard sed does not support the combination of 2 and g as flags to the s command).






    share|improve this answer




















    • 1





      with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

      – glenn jackman
      Mar 26 at 16:02






    • 2





      And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

      – glenn jackman
      Mar 26 at 16:04






    • 1





      @glennjackman Possibly, but it looks rather neat.

      – Kusalananda
      Mar 26 at 16:05











    • Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

      – Jon Red
      Mar 26 at 16:06











    • If I wasn't tied to using an array, however, this would be best solution.

      – Jon Red
      Mar 26 at 16:24













    10












    10








    10







    As far as I can see, there's no need to read it into a bash array to create that output:



    $ sed 's/[ "]//g; s/,/ /; s/,//g; s/ /,/; s/.*/|ELEMENT|&|/' <file
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|


    The sed expression deletes spaces and double quotes, replaces the first comma with a space (there are no other spaces in the string at this point), deletes all other commas, restores the first comma, and the prepends and appends the extra data.



    Alternatively, with GNU sed:



    sed 's/[ "]//g; s/,//2g; s/.*/|ELEMENT|&|/' <file


    (standard sed does not support the combination of 2 and g as flags to the s command).






    share|improve this answer















    As far as I can see, there's no need to read it into a bash array to create that output:



    $ sed 's/[ "]//g; s/,/ /; s/,//g; s/ /,/; s/.*/|ELEMENT|&|/' <file
    |ELEMENT|10,this|
    |ELEMENT|20,is|
    |ELEMENT|30,all|
    |ELEMENT|40,I|
    |ELEMENT|50,need2|
    |ELEMENT|60,see|


    The sed expression deletes spaces and double quotes, replaces the first comma with a space (there are no other spaces in the string at this point), deletes all other commas, restores the first comma, and the prepends and appends the extra data.



    Alternatively, with GNU sed:



    sed 's/[ "]//g; s/,//2g; s/.*/|ELEMENT|&|/' <file


    (standard sed does not support the combination of 2 and g as flags to the s command).







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 26 at 17:35

























    answered Mar 26 at 16:01









    KusalanandaKusalananda

    143k18267447




    143k18267447







    • 1





      with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

      – glenn jackman
      Mar 26 at 16:02






    • 2





      And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

      – glenn jackman
      Mar 26 at 16:04






    • 1





      @glennjackman Possibly, but it looks rather neat.

      – Kusalananda
      Mar 26 at 16:05











    • Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

      – Jon Red
      Mar 26 at 16:06











    • If I wasn't tied to using an array, however, this would be best solution.

      – Jon Red
      Mar 26 at 16:24












    • 1





      with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

      – glenn jackman
      Mar 26 at 16:02






    • 2





      And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

      – glenn jackman
      Mar 26 at 16:04






    • 1





      @glennjackman Possibly, but it looks rather neat.

      – Kusalananda
      Mar 26 at 16:05











    • Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

      – Jon Red
      Mar 26 at 16:06











    • If I wasn't tied to using an array, however, this would be best solution.

      – Jon Red
      Mar 26 at 16:24







    1




    1





    with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

    – glenn jackman
    Mar 26 at 16:02





    with GNU sed, you can use 's/,//2g to remove commas, starting with the 2nd

    – glenn jackman
    Mar 26 at 16:02




    2




    2





    And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

    – glenn jackman
    Mar 26 at 16:04





    And, the last 2 s/// commands can be s/.*/|ELEMENT|&|/ but that may be more effort for sed.

    – glenn jackman
    Mar 26 at 16:04




    1




    1





    @glennjackman Possibly, but it looks rather neat.

    – Kusalananda
    Mar 26 at 16:05





    @glennjackman Possibly, but it looks rather neat.

    – Kusalananda
    Mar 26 at 16:05













    Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

    – Jon Red
    Mar 26 at 16:06





    Yeah, this is part of a larger script. The array is necessary, not just for the output. Hence my interest in parameter substitution. I could loop over the array with this but that will be a nightmare to implement. Terndon provided a loop-free solution using sed that I'll likely fall back on if parameter substitution is a no-go.

    – Jon Red
    Mar 26 at 16:06













    If I wasn't tied to using an array, however, this would be best solution.

    – Jon Red
    Mar 26 at 16:24





    If I wasn't tied to using an array, however, this would be best solution.

    – Jon Red
    Mar 26 at 16:24











    9














    ELEMENT='50,n,e,e,d,2'
    IFS=, read -r first rest <<<"$ELEMENT"
    printf "%s,%sn" "$first" "$rest//,/"




    50,need2


    Get out of the habit of using ALLCAPS variable names. You'll eventually collide with a crucial "system" variable like PATH and break your code.






    share|improve this answer























    • Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

      – Jon Red
      Mar 26 at 16:14






    • 1





      I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

      – glenn jackman
      Mar 26 at 16:17






    • 1





      There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

      – Jeff Schaller
      Mar 26 at 16:19















    9














    ELEMENT='50,n,e,e,d,2'
    IFS=, read -r first rest <<<"$ELEMENT"
    printf "%s,%sn" "$first" "$rest//,/"




    50,need2


    Get out of the habit of using ALLCAPS variable names. You'll eventually collide with a crucial "system" variable like PATH and break your code.






    share|improve this answer























    • Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

      – Jon Red
      Mar 26 at 16:14






    • 1





      I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

      – glenn jackman
      Mar 26 at 16:17






    • 1





      There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

      – Jeff Schaller
      Mar 26 at 16:19













    9












    9








    9







    ELEMENT='50,n,e,e,d,2'
    IFS=, read -r first rest <<<"$ELEMENT"
    printf "%s,%sn" "$first" "$rest//,/"




    50,need2


    Get out of the habit of using ALLCAPS variable names. You'll eventually collide with a crucial "system" variable like PATH and break your code.






    share|improve this answer













    ELEMENT='50,n,e,e,d,2'
    IFS=, read -r first rest <<<"$ELEMENT"
    printf "%s,%sn" "$first" "$rest//,/"




    50,need2


    Get out of the habit of using ALLCAPS variable names. You'll eventually collide with a crucial "system" variable like PATH and break your code.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 26 at 16:00









    glenn jackmanglenn jackman

    53.4k673115




    53.4k673115












    • Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

      – Jon Red
      Mar 26 at 16:14






    • 1





      I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

      – glenn jackman
      Mar 26 at 16:17






    • 1





      There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

      – Jeff Schaller
      Mar 26 at 16:19

















    • Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

      – Jon Red
      Mar 26 at 16:14






    • 1





      I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

      – glenn jackman
      Mar 26 at 16:17






    • 1





      There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

      – Jeff Schaller
      Mar 26 at 16:19
















    Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

    – Jon Red
    Mar 26 at 16:14





    Not parameter substitution. BUT, I was unaware that ALLCAPS variable names was a bad habit in Bash. You make a good point, one that a cursory googling definitely confirms. Thank you for improving my style! :)

    – Jon Red
    Mar 26 at 16:14




    1




    1





    I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

    – glenn jackman
    Mar 26 at 16:17





    I've answer questions where the person wrote PATH=something; ls $PATH and then wondered about the ls: command not found error.

    – glenn jackman
    Mar 26 at 16:17




    1




    1





    There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

    – Jeff Schaller
    Mar 26 at 16:19





    There are nearly a hundred built-in variables that are named in all caps (click through this man page link) to see...

    – Jeff Schaller
    Mar 26 at 16:19











    8














    [This is essentially a more fully developed version of glenn jackmann's answer]



    Building an associative array from the stripped key and value, using the first comma as separator:



    declare -A arr
    while IFS=, read -r k v; do arr["$k//[ "]"]="$v//[ ,"]"; done < file.txt
    for k in "$!arr[@]"; do
    printf '|ELEMENT|%s,%s|n' "$k" "$arr[$k]"
    done
    |ELEMENT|20,is|
    |ELEMENT|10,this|
    |ELEMENT|50,need2|
    |ELEMENT|40,I|
    |ELEMENT|60,see|
    |ELEMENT|30,all|





    share|improve this answer



























      8














      [This is essentially a more fully developed version of glenn jackmann's answer]



      Building an associative array from the stripped key and value, using the first comma as separator:



      declare -A arr
      while IFS=, read -r k v; do arr["$k//[ "]"]="$v//[ ,"]"; done < file.txt
      for k in "$!arr[@]"; do
      printf '|ELEMENT|%s,%s|n' "$k" "$arr[$k]"
      done
      |ELEMENT|20,is|
      |ELEMENT|10,this|
      |ELEMENT|50,need2|
      |ELEMENT|40,I|
      |ELEMENT|60,see|
      |ELEMENT|30,all|





      share|improve this answer

























        8












        8








        8







        [This is essentially a more fully developed version of glenn jackmann's answer]



        Building an associative array from the stripped key and value, using the first comma as separator:



        declare -A arr
        while IFS=, read -r k v; do arr["$k//[ "]"]="$v//[ ,"]"; done < file.txt
        for k in "$!arr[@]"; do
        printf '|ELEMENT|%s,%s|n' "$k" "$arr[$k]"
        done
        |ELEMENT|20,is|
        |ELEMENT|10,this|
        |ELEMENT|50,need2|
        |ELEMENT|40,I|
        |ELEMENT|60,see|
        |ELEMENT|30,all|





        share|improve this answer













        [This is essentially a more fully developed version of glenn jackmann's answer]



        Building an associative array from the stripped key and value, using the first comma as separator:



        declare -A arr
        while IFS=, read -r k v; do arr["$k//[ "]"]="$v//[ ,"]"; done < file.txt
        for k in "$!arr[@]"; do
        printf '|ELEMENT|%s,%s|n' "$k" "$arr[$k]"
        done
        |ELEMENT|20,is|
        |ELEMENT|10,this|
        |ELEMENT|50,need2|
        |ELEMENT|40,I|
        |ELEMENT|60,see|
        |ELEMENT|30,all|






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 16:06









        steeldriversteeldriver

        38.2k45489




        38.2k45489





















            6














            You could loop over the array and use an intermediate variable:



            for((i=0; i < "$#ARRAY[@]"; i++))
            do
            rest="$ARRAY[i]#*,"
            ARRAY[i]="$ARRAY[i]%%,*","$rest//,/"
            done


            This assigns to rest the portion after the first comma; we then concatenate three pieces back into the original variable:



            • the portion before the first comma

            • a comma

            • the replacement in rest of every comma with nothing





            share|improve this answer























            • This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

              – Jon Red
              Mar 26 at 16:26






            • 1





              Fair enough; I just tried to answer within the limitations (parameter expansion only).

              – Jeff Schaller
              Mar 26 at 16:27















            6














            You could loop over the array and use an intermediate variable:



            for((i=0; i < "$#ARRAY[@]"; i++))
            do
            rest="$ARRAY[i]#*,"
            ARRAY[i]="$ARRAY[i]%%,*","$rest//,/"
            done


            This assigns to rest the portion after the first comma; we then concatenate three pieces back into the original variable:



            • the portion before the first comma

            • a comma

            • the replacement in rest of every comma with nothing





            share|improve this answer























            • This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

              – Jon Red
              Mar 26 at 16:26






            • 1





              Fair enough; I just tried to answer within the limitations (parameter expansion only).

              – Jeff Schaller
              Mar 26 at 16:27













            6












            6








            6







            You could loop over the array and use an intermediate variable:



            for((i=0; i < "$#ARRAY[@]"; i++))
            do
            rest="$ARRAY[i]#*,"
            ARRAY[i]="$ARRAY[i]%%,*","$rest//,/"
            done


            This assigns to rest the portion after the first comma; we then concatenate three pieces back into the original variable:



            • the portion before the first comma

            • a comma

            • the replacement in rest of every comma with nothing





            share|improve this answer













            You could loop over the array and use an intermediate variable:



            for((i=0; i < "$#ARRAY[@]"; i++))
            do
            rest="$ARRAY[i]#*,"
            ARRAY[i]="$ARRAY[i]%%,*","$rest//,/"
            done


            This assigns to rest the portion after the first comma; we then concatenate three pieces back into the original variable:



            • the portion before the first comma

            • a comma

            • the replacement in rest of every comma with nothing






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 16:01









            Jeff SchallerJeff Schaller

            45.4k1164147




            45.4k1164147












            • This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

              – Jon Red
              Mar 26 at 16:26






            • 1





              Fair enough; I just tried to answer within the limitations (parameter expansion only).

              – Jeff Schaller
              Mar 26 at 16:27

















            • This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

              – Jon Red
              Mar 26 at 16:26






            • 1





              Fair enough; I just tried to answer within the limitations (parameter expansion only).

              – Jeff Schaller
              Mar 26 at 16:27
















            This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

            – Jon Red
            Mar 26 at 16:26





            This was my first thought and is simple enough for the example but this is part of larger script where the array is massive and there's already loops and it would be a whole thing. This would definitely work but would be very cumbersome to implement in the larger project I'm working on.

            – Jon Red
            Mar 26 at 16:26




            1




            1





            Fair enough; I just tried to answer within the limitations (parameter expansion only).

            – Jeff Schaller
            Mar 26 at 16:27





            Fair enough; I just tried to answer within the limitations (parameter expansion only).

            – Jeff Schaller
            Mar 26 at 16:27

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f508777%2fusing-parameter-substitution-on-a-bash-array%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum

            He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

            Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029