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    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to