Timeline for Bash array with spaces in elements
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 11, 2022 at 3:24 | comment | added | zhy2002 | bash array index is 1-based | |
Jul 8, 2019 at 19:46 | comment | added | mcint |
${FILES[@]} returns the contents of the array. ${#FILES[@]} returns the count of elements in the array. (self-contained answer).
|
|
Dec 11, 2018 at 18:08 | comment | added | Dan Fego | I answered this six years ago but I believe it's to get the count of the number of elements in the array FILES. | |
Dec 11, 2018 at 13:28 | comment | added | Michal Vician |
Whats does the sharp (# ) symbol do in for ((i = 0; i < ${#FILES[@]}; i++)) statement?
|
|
Sep 7, 2016 at 12:24 | comment | added | Michael Shaw | @MarkEdgar i experiencing problems with for f in ${FILES[@]} when the array members have spaces. It seems that the whole array is reinterpreted again, with the spaces spitting your existing members into two or more elements. It seems the " " are very important | |
Feb 1, 2012 at 2:44 | comment | added | Mark Edgar |
It's not necessary to loop over the indexes when you can loop over the elements with for f in "${FILES[@]}" .
|
|
Jan 31, 2012 at 19:36 | history | edited | Dan Fego | CC BY-SA 3.0 |
added 2 characters in body
|
Jan 31, 2012 at 19:35 | comment | added | Gordon Davisson |
Note that you should use double-quotes when you use the array elements (e.g. echo "${FILES[$i]}" ). It doesn't matter for echo , but it will for anything that uses it as a filename.
|
|
Jan 31, 2012 at 17:55 | vote | accept | abelenky | ||
Jan 31, 2012 at 17:54 | history | answered | Dan Fego | CC BY-SA 3.0 |