[Top][All Lists]

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

bash can't distinguish between empty and unset arrays

From: Martijn Dekker
Subject: bash can't distinguish between empty and unset arrays
Date: Wed, 03 Feb 2016 23:43:37 +0000
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

bash treats an empty array as if it were an unset variable, which seems
very illogical as empty is quite distinct from unset:

$ myarray=()
$ [[ -v myarray ]] && echo set || echo unset
$ set | grep ^myarray=  # yet, it's set:
$ set -u
$ for i in "address@hidden"; do :; done
bash: address@hidden: unbound variable

Note also that the "unbound variable" error is inconsistent with the
behaviour of "$@"; I would have thought that, logically, "$@" and
"address@hidden" should behave the same way, since arrays are implemented as a
logical extension of the positional parameters concept.

zsh and ksh93 can distinguish between empty and unset arrays.


- Martijn

reply via email to

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