bug-bash
[Top][All Lists]
Advanced

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

Re: Global variable modification by nameref chain


From: Chet Ramey
Subject: Re: Global variable modification by nameref chain
Date: Sun, 12 Jun 2016 21:33:17 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.1.1

On 6/9/16 6:06 AM, Dan Douglas wrote:

>  $ bash -c 'typeset -n a=b b; b=a[1]; a=foo; typeset -p a b' # bash 4.3
> declare -a a='([1]="foo")'
> declare -n b="a[1]"
>  $ ./bash -c 'typeset -n a=b b; b=a[1]; typeset -p a b; a=foo' # 4.4
> declare -n a="b"
> declare -n b="a[1]"
> ./bash: line 0: `a[1]': not a valid identifier
> 
> (That's the confusing error mentioned previously btw)

There are a few ways we can go on this.  Using your script

$ cat x1
typeset -n a=b b
b=a[1]
typeset -p a b
a=foo
typeset -p a b

we can

1. Honor the nameref attribute and reject the assignment, as the current
   devel git branch does:

$ ../bash-20160603/bash ./x1
declare -n a="b"
declare -n b="a[1]"
./x1: line 4: `a[1]': not a valid identifier
declare -n a="b"
declare -n b="a[1]"

2. Honor the assignment and remove the nameref attribute, treating the
   variable as a scalar:

$ ./bash ./x1
declare -n a="b"
declare -n b="a[1]"
./x1: line 4: warning: a: removing nameref attribute
declare -a a=([0]="b" [1]="foo")
declare -n b="a[1]"

3. Honor the assignment and delete the nameref variable, creating a new
   one, like bash-4.3:

$ ../bash-4.3-patched/bash ./x1
declare -n a="b"
declare -n b="a[1]"
declare -a a='([1]="foo")'
declare -n b="a[1]"

4. Honor the assignment and remove the nameref attribute and value, but
   with a warning:

$ ./bash ./x1
declare -n a="b"
declare -n b="a[1]"
./x1: line 4: warning: a: removing nameref attribute
declare -a a='([1]="foo")'
declare -n b="a[1]"

5. The bizarre ksh93 behavior is always an option:

$ ksh93 ./x1
typeset -n a=.deleted
typeset -n -a b=('b[1]')
./x1: line 4: .deleted: is read only



-- 
``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/



reply via email to

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