Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: list last modified files



On Thu, 20 Aug 2015 08:34:31 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Aug 20,  2:29pm, Peter Stephenson wrote:
> }
> } On Thu, 20 Aug 2015 15:08:02 +0200
> } rooom <rooom@xxxxxxxxxxx> wrote:
> } > BTW, what is 'in'?
> } 
> } It's simply a syntactic marker specific to "for" which looks for it in
> } the list of arguments.  In the original shell syntax it's not
> } really doing much except make it a bit more readable since you're forced
> } to use "for var in ...", but zsh makes a virtue of it by allowing you
> } to do "for var1 var2... in ..." --- unless your variable is called "in",
> } obviously, in which case you can't.
> 
> Well ...

If you mean you'd rather blind me with code than state the rule...
that worked.

The rule is roughly:
- Assume the first argument is a variable.  This is needed for
backwards compatibility.  Note you can't do:
  vars=(one two three)
  for $vars in 1arg1 2arg1 3arg1 1arg2 2arg2 3arg2; ...
- Otherwise, look for more variables until a word matches "in"
(ignoring crazy variant zsh syntax)
- If no "in", use positional parameters.
- Otherwsie, any words after "in" are the arguments to loop over,
taken in batches of the number of arguments before "in".  The
words are no longer subject to anything more than normal argument
processing.

The rule means this does work:

  set -- 1 2 3 4 5 6
  for one two three; do
    print $one $two $three
  done

1 2 3
4 5 6

and you can replace "one" by "in" if you lke, but don't.

pws



Messages sorted by: Reverse Date, Date, Thread, Author