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

Re: Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)



On Tue, Dec 5, 2017 at 12:06 AM, Tom M. <boojum@xxxxxxxxxxxxxxxxxxx> wrote:
>> $ true; echo ${${=:-green red}[2-!?]}
>> green
>> $ false; echo ${${=:-green red}[2-!?]}
>> red
>
> The above fails for me:
> [...]
> And if run from zsh -f:
> % true; echo ${${=:-green red}[2-!?]}
> zsh: no such event: ]}

Stephane has forgotten that he has "setopt nobanghist".

You can get the same effect with $? except the sense is reversed:

% true; echo ${${=:-green red}[2-$?]}
red
% false; echo ${${=:-green red}[2-$?]}
green

This avoids the issue with banghist, but beware of commands that
return other than 0 or 1 for success/failure.



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