bug-bash
[Top][All Lists]
Advanced

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

Re: bash can't distinguish between empty and unset arrays


From: Reuti
Subject: Re: bash can't distinguish between empty and unset arrays
Date: Thu, 4 Feb 2016 01:13:00 +0100

Hi,

Am 04.02.2016 um 00:43 schrieb Martijn Dekker:

> 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
> unset

Which version of bash are you using?


> $ set | grep ^myarray=        # yet, it's set:
> myarray=()
> $ set -u

Doesn't -u force just the behavior you observe, what if using +u?

-- Reuti


> $ for i in "${x[@]}"; do :; done
> bash: x[@]: unbound variable
> 
> Note also that the "unbound variable" error is inconsistent with the
> behaviour of "$@"; I would have thought that, logically, "$@" and
> "${x[@]}" 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.
> 
> Thanks,
> 
> - Martijn
> 




reply via email to

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