I have an expression -z ${VAR_NAME+x}
which I know will check if ${VAR_NAME+x}
is an empty string. But I can't find out what is the purpose of having the +x
.
Asked
Active
Viewed 49 times
0

Cyrus
- 84,225
- 14
- 89
- 153

Kevin Winata
- 443
- 2
- 10
-
1https://wiki.bash-hackers.org/syntax/pe – Charles Duffy Aug 23 '19 at 01:32
-
1`test -z ${VAR_NAME+x}` is buggy. It should be `test -z "${VAR_NAME+x}"` *with the quotes*, or you end up with `test -n -z` (as `-n` is the default operator when `test` is called with only one argument), not `test -z ""` in that same case. Sure, they come out with the same result, but they work very different ways, so writing it without the quoting makes someone puzzle out the mechanism before they know *that* it works correctly. – Charles Duffy Aug 23 '19 at 01:34
-
BTW, `-z` is explicitly a *test* expression (an argument to [the command `test`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html), whether under its own name or the synonym `[`), vs bash syntax as such; bash has a built-in implementation of `test` which gets used in practice instead of `/bin/[` or `/bin/test`, but that's a performance optimization, not a difference that impacts semantics. – Charles Duffy Aug 23 '19 at 01:55