help-bash
[Top][All Lists]
Advanced

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

Re: Is ${x+word} documented?


From: Peng Yu
Subject: Re: Is ${x+word} documented?
Date: Sun, 31 Jan 2021 09:51:25 -0600

OK. I missed it, as I don't see it in the listing. But it seems to be
more intuitive to list everything in the listing. This makes it easier
to look up things.

On Sun, Jan 31, 2021 at 12:21 AM Koichi Murase <myoga.murase@gmail.com> wrote:
>
> 2021年1月31日(日) 14:14 Peng Yu <pengyu.ut@gmail.com>:
> > I don't find the usage of `${x+word}` documented in the manpage (in
> > the Parameter Expansion section). Do I miss something here?
>
> It's documented. See the following description in the manual:
>
> -----
> > From 
> > https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
> >
> > Omitting the colon results in a test only for a parameter that is
> > unset. Put another way, if the colon is included, the operator tests
> > for both parameter’s existence and that its value is not null; if
> > the colon is omitted, the operator tests only for existence.
> -----
>
> > Can I always assume ${x:+word} and ${x+word} are exactly the same?
>
> No. They behave differently when the variable x is defined but has an
> empty value.
>
> $ x=1; echo "[${x+word}][${x:+word}]"
> [word][word]
> $ x=; echo "[${x+word}][${x:+word}]"
> [word][]
> $ unset x; echo "[${x+word}][${x:+word}]"
> [][]
>
> --
> Koichi



-- 
Regards,
Peng



reply via email to

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