Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15257
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: T/F var expansion? |
| Date | 2019-07-29 10:28 +0100 |
| Message-ID | <mailman.115.1564401917.1985.bug-bash@gnu.org> (permalink) |
| References | <5D3E7367.8050308@tlinx.org> <20190729092815.o5ihuawg7rgekqs2@chaz.gmail.com> |
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
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: T/F var expansion? Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-07-29 10:28 +0100
csiph-web