[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Referencing empty array with "set -u" active throws error
From: |
Chet Ramey |
Subject: |
Re: Referencing empty array with "set -u" active throws error |
Date: |
Sat, 18 Dec 2010 11:41:44 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 |
On 12/17/10 4:48 AM, jens.schmidt35@arcor.de wrote:
> Bash Version: 4.1
> Patch Level: 0
> Release Status: release
>
> Description:
> Referencing empty array with "set -u" active throws unbound variable error.
>
> Repeat-By:
> $ set -u
> $ declare -a array
> $ array=( )
> $ echo "${array[@]}"
> bash: array[@]: unbound variable
A variable isn't set until it's been assigned a value.
> For an empty "$@" this does not throw an "unbound" error, which seems to be
> an inconsistent behaviour to me.
Bash used to do this, but Posix declared that $@ and $* are exceptions
to the unset variable rule.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/