zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: list last modified files
Date: Thu, 20 Aug 2015 16:55:52 +0100	[thread overview]
Message-ID: <20150820165552.2b5ec817@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <150820083431.ZM29050@torch.brasslantern.com>

On Thu, 20 Aug 2015 08:34:31 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Aug 20,  2:29pm, Peter Stephenson wrote:
> }
> } On Thu, 20 Aug 2015 15:08:02 +0200
> } rooom <rooom@prokonto.pl> 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


  reply	other threads:[~2015-08-20 15:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-19 21:59 rooom
2015-08-19 23:16 ` Vin Shelton
2015-08-20  4:33 ` Bart Schaefer
2015-08-20  5:20   ` Mikael Magnusson
2015-08-20 13:08   ` rooom
2015-08-20 13:29     ` Peter Stephenson
2015-08-20 15:34       ` Bart Schaefer
2015-08-20 15:55         ` Peter Stephenson [this message]
2015-08-20 17:13           ` Bart Schaefer
     [not found]         ` <20150820165552.2b5ec817__22391.7863135741$1440086232$gmane$org@pwslap01u.europe.root.pri>
2015-08-20 16:42           ` Stephane Chazelas
2015-08-20 17:09             ` Bart Schaefer
2015-08-23 20:35     ` ZLE: missing edit-buffer widget rooom
2015-08-23 21:45       ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150820165552.2b5ec817@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).