Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)
On 25 Nov 2017 at 12:15:42, Sebastian Gniazdowski (psprint@xxxxxxxxxxx) wrote:
> if (VAR) { return "" } else { return "something else" }
Kept the main point of previous messages. New point – it is actually possible to have ternary expression in Zsh:
% var=abc
% echo ${${${(M)var#abc(#e)}:+ternary1}:-ternary2}
ternary1
% var=abcd
% echo ${${${(M)var#abc(#e)}:+ternary1}:-ternary2}
ternary2
It's a one-liner "If val is xyz, then substitute". Pretty neat thing, maybe there are similar tricks possible? I have to implement something and cannot fiddle with this now.
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
Messages sorted by:
Reverse Date,
Date,
Thread,
Author