Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14361

Re: namerefs and environment variable names with subscripts

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: namerefs and environment variable names with subscripts
Date 2018-07-18 14:51 -0400
Message-ID <mailman.3771.1531939924.1292.bug-bash@gnu.org> (permalink)
References <CAMu=BrrS1cGwX2mWqULg_2xHs9r=LZRmjcEwfYePc6Q+n7jYwg@mail.gmail.com>

Show all headers | View raw


On 7/17/18 4:44 PM, Grisha Levit wrote:
> The following commands:
> 
>     declare -n r=v[0]
>     v=(X); r=Y
>     declare -p ${!v*}
>     printf "%s: <%s>\n" "r" "$r" "v" "$v"
> 
> Will normally produce the following output:
> 
>     declare -a v=([0]="Y")
>     r: <Y>
>     v: <Y>
> 
> However, if we start bash with `v[0]' already in the environment, such as with:
> 
>     env 'v[0]=' $BASH
> 
> The behavior changes, and the output is:
> 
>     declare -a v=([0]="X")
>     declare -x v[0]="Y"
>     r: <Y>
>     v: <X>
> 
> I would expect namerefs to ignore any variables with the literal name
> `v[0]' in the environment rather than follow them.

Thanks. Bash needs to better segregate environment variables that aren't
valid shell identifiers.

Chet

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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: namerefs and environment variable names with subscripts Chet Ramey <chet.ramey@case.edu> - 2018-07-18 14:51 -0400

csiph-web