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

Re: Solved, but now a new twist (was: Double Evaluation Question (not in FAQ))

Bart Schaefer wrote:
> On Sep 4, 10:43am, Com MN PG P E B Consultant 3 wrote:
> }
> } That is, if I have an assignment
> } 
> }   x='~linus    ~steve'
> } 
> } Is there also a simple solution, which expands $x to the home
> } directories of linus and steve, with spacing preserved?
> There's a complicated solution:
> setopt extendedglob
> print -r ${(j//)${(s/|/)~${x/(#b)( ##)/|$match|}}}
> I'm actually a little surprised that this works -- I would have
> guessed that joining with (j//) took place before tilde expansion.
> But it seems to work as far back as backreferences (#b) do, so I
> guess it's safe to assume it'll keep working.  (PWS, does something
> need to be added to the "Rules" section under "Parameter Expansion"?)

I think (though I haven't checked) that it's because of the prefork() in
multsub(), which gets called for subexpressions.  This means that all
forms of $-style expansion as well as ` and ~/= expansion get handled at
each level at which a nested ${...} is processed.  Yes, this probably
ought to be documented if anyone understood it well enough.

Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/

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