Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)
- X-seq: zsh-workers 42080
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)
- Date: Tue, 5 Dec 2017 01:04:58 -0800
- Cc: "Tom M." <boojum@xxxxxxxxxxxxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=yERSvDuCqwA3lzPQAn0OQlKTf4ay7ZK7pwEgI8IMv9M=; b=CZtIICbBEeUtKNpBnTAKQIOxfAzYhQepAc9cc7cw+XdneDRYbRk8L9L9+OaHErhuJB Wyc9ckVikcTNYN7+gpavg4LRnWaVZ9UO/IQFCLYIyFclymLwJIIU1vGwgL5dFAzO5sCH SC3b5lHdA1JveJQXLYOgUNZ1Q7SIK3tUBxF7Fxq3KyYhw3NUggbqFYr8HU+n4T3SusPL bRvalO+jDyX6KdaCGgGfp64gUrk9ZNbG02pkD/0iNF69HGXmtOmORVj3zVMCpQNQn70j 7Tw5eNzclIVLlCLDHvS12z3joy44+dz1uI8dbzLnIUKfLhVBJ+fMgVJGlP2y1Litjs+A 7vLg==
- In-reply-to: <CACfAdfYgAjNR7AWTLtF=zLMF5vOgOpzxJHQznf1K-O=YX797ww@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <etPan.5a107666.74b42c6c.137@zdharma.org> <etPan.5a107a4b.459f7f60.137@zdharma.org> <etPan.5a10805d.57d72d7c.137@AirmailxGenerated.am> <etPan.5a1950df.46f9693d.c73c@zdharma.org> <etPan.5a23bfae.35a1d3d8.c73c@zdharma.org> <20171205065518.GA7087@chaz.gmail.com> <CACfAdfYgAjNR7AWTLtF=zLMF5vOgOpzxJHQznf1K-O=YX797ww@mail.gmail.com>
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.
- References:
- Feature request – substitutions similar to +, -, :+, :-
- From: Sebastian Gniazdowski
- Re: Feature request – substitutions similar to +, -, :+, :-
- From: Sebastian Gniazdowski
- Re: Feature request – substitutions similar to +, -, :+, :-
- From: Sebastian Gniazdowski
- Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)
- From: Sebastian Gniazdowski
- Re: Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)
- Re: Ternary expression in Zsh (was: Feature request – substitutions similar to +, -, :+, :-)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author