bug-bash
[Top][All Lists]
Advanced

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

Re: param expansion with single-character special vars in the environmen


From: Piotr Grzybowski
Subject: Re: param expansion with single-character special vars in the environment
Date: Wed, 27 Apr 2016 23:22:46 +0200

On 27 Apr 2016, at 21:49, Eduardo A. Bustamante López wrote:

> 
> Actually, this seems to be a special case, just because '5' is an invalid
> variable name. But the problem still exists:
> 
> |  dualbus@hp ...src/gnu/bash % ./bash -c 'declare -r RO=x; r=$RO; declare -n 
> r; x=y; declare -n RO; RO=z; declare -p RO; echo "$RO"'
> |  declare -nr RO="x"
> |  z

 ok lets take a look:

> declare -r RO=x; r=$RO;

 a read only variable RO and variable r with value "x"

> declare -n r;

from now on every assignment to r assigns to variable of name x

> x=y;

variavle of name x has value y

> declare -n RO;

here you make RO a nameref, from now on assignments to RO are not assignments 
to readonly variable RO but to variable of name "$RO" in this case variable x

> RO=z;

assigment to variable x via a nameref called RO

> declare -p RO; echo "$RO"

print the value of the variable referenced to by $RO, in that case x.
No assignment to readonly variables whatsoever. 
if you want to make a nameref that has the same name as the readonly variable, 
feel free.
 The only bug I see, is the apparent impossibility of removing the nameref from 
readonly variable, I assure you, if you could remove the nameref from RO you 
would recover "x" because it is still there in the entry of variables table, as 
seen by declare -p.
 I do not see other bug here.
 What do you think?

cheers,
pg





reply via email to

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