Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 10
    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. Commented Jan 31, 2012 at 19:35
  • 36
    It's not necessary to loop over the indexes when you can loop over the elements with for f in "${FILES[@]}".
    – Mark Edgar
    Commented Feb 1, 2012 at 2:44
  • 12
    @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 Commented Sep 7, 2016 at 12:24
  • 1
    Whats does the sharp (#) symbol do in for ((i = 0; i < ${#FILES[@]}; i++)) statement? Commented Dec 11, 2018 at 13:28
  • 4
    I answered this six years ago but I believe it's to get the count of the number of elements in the array FILES.
    – Dan Fego
    Commented Dec 11, 2018 at 18:08