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

Re: no way to keep my glob expanded ? (i don't think so)



Marc Chantreux wrote:
> hello zsh lovers,
> ${${:-*c}//truc/}  see *c as a string so the result is *c

> Clint and Peter explained me in another post that the subsitution is
> applied first. So: 
> 
> print ${${:-*c}//truc/}
> => print ${"*c"//truc/}
> => print "*c"
> 
> as i understood thinks, it's impossible to do what i expected.

Yes, that's right.  Variable handling is always done before globbing.
Once globbing is expanded the argument list is fully prepared.

> ft gave a workaround on #zsh: print -l *c(e-'REPLY=${REPLY//truc/}'-)

As Mikael explained, you can also use history-style modifiers in glob
qualifiers, which are more readable.  I think *c(:gs/truc//) is the
best answer you are likely to get.

> - is it a way to visualize those multipass transformations ?

There's a long (but still probably incomplete) description of how the
parameter transformations work in zshexpn: search for "brain damage".

As to how the different types of expansion are ordered, this is stated
rather than explained at the top of the same manual page:  the
expansions are performed in order.  The main subtlety is whether the
parameter expansion produces further expandable results, or just
strings, as controlled by the GLOB_SUBST option.

> - is there a way to tell to zsh to work as expected ?

If you mean you expect the shell to perform globbing in the middle of
parameter expansion then no, that's just not how shells work.  If you
insist on using a parameter expansion syntax you need something that
produces an extra expansion phase, which will be clumsy, such as using
an intermediate array or a $(...) expansion which can be nested in
parameter expansion (e.g. ${$(print *c)//truc/} ) but will fork a subshell
to do its own expansion.

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



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