[Top][All Lists]

[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: Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2

On 12/17/10 4:48 AM, address@hidden 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 "address@hidden"
>   bash: address@hidden: 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.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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