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

Re: PATCH: new parameter expansion type?



"Bart Schaefer" wrote:
> On Aug 30, 11:49am, Sven Wischnowsky wrote:
> } Subject: PATCH: new parameter expansion type?
> }
> }   ${name^pattern^then^else}
> } 
> } Gives you the (substituted) `then' string if the expansion of `name'
> } matches the `pattern' and otherwise it gives you the `else' string.
> 
> Isn't this just the same as
> 
> 	${${${(M)name#pattern}:+then}:-else}
> 
> except of course that you have to be a little selective about whether
> you use # or % to delimit the pattern?

This seems to be the case; I've included it in 6-pws-2, but I'll probably
back it off in 6-pws-3, unless there's a good reason otherwise.

I was thinking about a more general ternary expression syntax, which would
require doing some work to pre-expansion argument lists.  Something like

${[[ <test> ]] <true1> <true2> ... | <false1> <false2> ... }

i.e. the true/false bits are treated like part of an ordinary argument list
(but can't have redirections).  I suspect it's going to be too clumsy,
however.  You can get the same effect with if's and arrays, obviously.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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