Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15257 > unrolled thread

Re: T/F var expansion?

Started byStephane Chazelas <stephane.chazelas@gmail.com>
First post2019-07-29 10:28 +0100
Last post2019-07-29 10:28 +0100
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: T/F var expansion? Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-07-29 10:28 +0100

#15257 — Re: T/F var expansion?

FromStephane Chazelas <stephane.chazelas@gmail.com>
Date2019-07-29 10:28 +0100
SubjectRe: T/F var expansion?
Message-ID<mailman.115.1564401917.1985.bug-bash@gnu.org>
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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web