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*

4
  • 1
    Learnt a lot from this answer. Thanks. I really boiled this question down for simplicity. I am actually trying to loop through files in a directory with some wildcard matching, in a script that must work in bash and zsh. I'll post that as a separate question. Commented Aug 8, 2018 at 20:22
  • 1
    @BruceJohnson unix.stackexchange.com/questions/38172/… Commented Aug 8, 2018 at 20:51
  • In the file pattern example, isnt that glob expanded and assigned to file_pattern by bash? Before it ever gets expanded by $file_pattern? Commented Aug 9, 2018 at 1:38
  • @D.BenKnoble, no. Try f=*; echo "$f" in bash. That's an assignment to a scalar variable, which can contain only one value. You'd need f=(*) as shown, that is do an array variable assignment for a variable to contain any number of values. Commented Aug 9, 2018 at 5:59