bug-bash
[Top][All Lists]
Advanced

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

Re: unset does not act as expected on namerefs


From: Eduardo A . Bustamante López
Subject: Re: unset does not act as expected on namerefs
Date: Tue, 26 May 2015 11:00:45 -0500
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, May 26, 2015 at 05:47:30PM +0200, Geir Hauge wrote:
[...]
> The surprising part is that it keeps the -n flag, but partially loses
> the nameref ability:
> 
> $ var=foo; declare -n ref
> $ ref=var
> $ printf '%s - ' "$ref"; declare -p ref
> foo - declare -n ref="var"
> $ unset ref
> $ ref=var
> $ printf '%s - ' "$ref"; declare -p ref
> var - declare -n ref="var"
> $ ref=baz
> baz - declare -n ref="var"

I'm not so sure about that. Let's see it, step by step:

# Here, we setup the whole thing, and everything works as expected. 'ref'
points to 'var', and the value printed is that of 'var'.
dualbus@hp:~$ var=foo; declare -n ref=var; echo "$ref"; declare -p ref
foo
declare -n ref="var"

# Here we 'unset ref', which actually unsets 'var'. Then, we assign 'var' to
# 'ref', but since 'ref' is still a nameref, it instead assigns 'var' to 'var'.
dualbus@hp:~$ unset ref; ref=var; echo "$ref"; declare -p ref
var
declare -n ref="var"
dualbus@hp:~$ declare -p var
declare -- var="var"

# Here you assign 'baz' to 'var', through 'ref'. It works as documented.
dualbus@hp:~$ ref=baz; echo "$ref"; declare -p ref var
baz
declare -n ref="var"
declare -- var="baz"

-- 
Eduardo Bustamante
https://dualbus.me/



reply via email to

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