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