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

Re: assigning parameters and globbing



Vincent Lefevre wrote:
> Is it normal that this doesn't work?
> 
> dixsept% setopt GLOB_ASSIGN
> dixsept% export BLAH=*([-1])
> zsh: no matches found: BLAH=*([-1])

Yes, it is.  Assignments inside builtins have always been a bit fraught
since the arguments are parsed as normal arguments, which is a rather
different mechanism from the way stand-alone assignments are handled.

There are a few exceptions, for example ~'s are handled immediately
after the = and after colons for PATH-like variables, and word-splitting
isn't done in cases like

  export foo=$(echo two words)

which would strictly expand to

  export foo=two words

which probably isn't what you meant.

However, there's never been any attempt to handle arrays in that
position, so it's not only GLOB_ASSIGN that doesn't work; no form of
array assignment works after typeset and friends.

Note that the syntax you're using relies on array handling even though
you're explicitly extracting a single element at the end, and even
though it's smart enough to make BLAH a scalar in the case of a normal
assignment.  Indeed, GLOB_ASSIGN is vaguely deprecated (meaning there
are no plans to remove it but it's safer not to use it) partly because
you can't predict if the result of the assignment is a scalar or an
array.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



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