Timeline for What is the difference between [@] and [*] when referencing bash array values?
Current License: CC BY-SA 4.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 16, 2023 at 11:00 | comment | added | envs_h_gang_5 | stackoverflow.com/a/3348659/19166437 | |
| S Apr 28, 2021 at 11:46 | history | suggested | CommunityBot | CC BY-SA 4.0 | fix typo so it is correct |
| Apr 28, 2021 at 11:15 | review | Suggested edits | |||
| S Apr 28, 2021 at 11:46 | |||||
| Mar 26, 2021 at 12:23 | history | edited | ilkkachu | CC BY-SA 4.0 | improve phrasing, note that the behaviour is similar between array indexing and the special parameters * and @ |
| Mar 25, 2021 at 9:46 | comment | added | conny | Yes and note that it is the surrounding double quotes that in turn preserves the "${LIST[*]}" as "1 2 3" and prevents it from getting split one more time into "1" "2" "3". Always double quote variable expansions UNLESS YOU WANT a spaces in their expanded value to cause splitting. | |
| Oct 9, 2020 at 10:25 | history | edited | AdminBee | CC BY-SA 4.0 | Minor change to formatting |
| Sep 15, 2020 at 9:54 | comment | added | Brent Rittenhouse | Hey, check it out! i.imgur.com/WYYtdvQ.png. It totally worked. Script is: IFS=" " && read -a arrBefore; IFS="/" && for i in "${arrBefore[*]}"; do echo "$i"; done; | |
| Sep 15, 2020 at 9:35 | comment | added | Brent Rittenhouse | Wow, it's worth while mentioning that when you do the one with the star that it separates the values by the value of "IFS". For example, try this: IFS="/" && LIST=(1 2 3); for i in "${LIST[*]}"; do echo "$i"; done; and you should get "1/2/3". Hell, if you couldn't remember any other method you could use this replace a character now that I think about it by setting IFS to the before character, splitting it using read -a <<< '$string", and then changing the IFS to the replacement before looping through and reconstructing it. Rather brute force but still... | |
| Mar 22, 2019 at 13:47 | comment | added | fraxture | What does it mean for something to be dealt with as one versus multiple variables? I wonder if you could provide a practical example to illustrate the difference. | |
| Jan 17, 2015 at 16:05 | vote | accept | arjan | ||
| Jun 7, 2014 at 14:45 | comment | added | arjan | Do you know where the difference between echo and printf comes from? Because with printf in the for loop, the * list reference is treated as multiple variables. | |
| Jun 7, 2014 at 14:38 | history | edited | Nidal | CC BY-SA 3.0 | deleted 4 characters in body |
| Jun 7, 2014 at 14:27 | history | answered | Nidal | CC BY-SA 3.0 |