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.

Required fields*

6
  • 9
    Also, assuming an array of names fnames=( a.txt b.txt c.txt ) you can use the syntax for f in ${fnames[@]}; do echo $f; done. Commented Sep 8, 2012 at 19:12
  • 1
    Is it true that for fname in a.txt b.txt c.txt and for fname in "a.txt" "b.txt" "c.txt" yield identical results? Commented Sep 8, 2012 at 19:39
  • Andrew, yes it is true. They will yield identical results Commented Sep 8, 2012 at 20:29
  • 1
    Of course you should use for f in "${fnames[@]}"; do echo $f; done (with quotes around ${fnames[@]}) if the fnames values might contain whitespace.  And you should use "$f", especially if you're doing anything more sophisticated than echo (e.g., cat or cp). (And even if you're only doing echo, you should use printf instead.) Commented Apr 23, 2016 at 21:02
  • I think @user13742 should be also noted in the answer. Commented Jan 13, 2018 at 4:53