bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: T/F var expansion?


From: Stephane Chazelas
Subject: Re: T/F var expansion?
Date: Mon, 29 Jul 2019 10:28:15 +0100
User-agent: NeoMutt/20171215

2019-07-28 21:17:43 -0700, L A Walsh:
> Is there a T/F var expansion that does:
>  
>     var=${tst:+$yes}${tst:-$no}
> 
> but with yes/no in 1 expansion?
[...]

You can also do:

no_yes=(no yes)
echo "${no_yes[${var+1}]}"

For the reverse:

echo "${no_yes[!0${var+1}]}"

See also:

map=(unset empty non-empty)
echo "${map[${var+1}+0${var:+1}]}"

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]