[Top][All Lists]

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

Re: correct error message?

From: Chet Ramey
Subject: Re: correct error message?
Date: Tue, 29 Nov 2016 11:40:15 -0800
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.5.0

On 11/26/16 1:01 PM, L A Walsh wrote:

> But this didn't (misspelling of hash name):
>>  if [[ ${requirs[xxx]:-} ]]; then echo ok; else echo not; fi
> bash: xxx: unbound variable
> Shouldn't it have said:
> bash: requirs: unbound variable?

No.  Bash performs array referencing `inside out', and always has.  When
asked to find the value for ${var[sub]}, bash first looks at `var' only
to find out what kind of expansion `sub' has to undergo.  In all cases, it
expands `sub' for compatibility with other shells that implement arrays
(primarily ksh93), because callers expect the side effects involved in
expanding the array subscript to take place.  In this case, it performs
arithmetic expansion on the subscript, which involves expanding identifiers
as variables, resulting in the `unbound variable' message.

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

reply via email to

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