Re: bash test ?

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

On Wed, Apr 19, 2023 at 07:50:29AM +0200, lejeczek via CentOS wrote:
Hi guys.

I cannot wrap my hear around this:

-> $ unset _Val; test -z ${_Val}; echo $?
-> $ unset _Val; test -n ${_Val}; echo $?
-> $ _Val=some; test -n ${_Val}; echo $?

What is this!?
How should two different, opposite tests give the same result
Is there some bash option which affects that and if so, then
what would be the purpose of such nonsense?

many thanks, L.

Quoted $_Val expands to a null, zero length string.
Unquoted $_Val expands to nothing which is different.

An alternative test with double square brackets would
give you your expected results as it automatically
quotes unquoted variables.

$ unset _Val ; [[ -n $_Val ]] ; echo $?


Jon H. LaBadie                  jcu@xxxxxxxxxx
CentOS mailing list

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]

  Powered by Linux