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: Geir Hauge
Subject: Re: unset does not act as expected on namerefs
Date: Tue, 26 May 2015 17:47:30 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, May 26, 2015 at 11:24:57AM -0400, Shawn Wilson wrote:
> On +2015/05/26 11:04:38, Greg Wooledge wrote:
> > On Tue, May 26, 2015 at 10:31:34AM -0400, Shawn Wilson wrote:
> > > swilson@swlap1:~/temp$ bash --version
> > > GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
> > > swilson@swlap1:~/temp$ cat t.txt 
> > > $ome text !n a file|
> > > swilson@swlap1:~/temp$ unset t
> > > swilson@swlap1:~/temp$ t=$(< ./t.txt)
> > > swilson@swlap1:~/temp$ echo "$t"
> > > bash: $ome text !n a file|: invalid variable name for name reference
> > > swilson@swlap1:~/temp$ var=foo; declare -n t; t=var; unset t; echo "$t"
> > > bash: $ome text !n a file|: invalid variable name for name reference
> > 
> > As surprising as that is, have a look at "help unset":
> > 
> 
> So current behavior should stand? I would think that unset (with no
> options) should DWIM. This behavior also seemed to surprise most on
> #bash IRC. This is not a bug for lack of documentation or not
> understanding the results after looking at the doc, but a "wow, this
> is surprising - maybe this could behave in a manner so it's not so
> surprising".

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"

-- 
Geir Hauge



reply via email to

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