On Sat, Aug 30, 2014 at 12:02:33PM +0800, lolilolicon wrote:
> > #!/bin/bash
> > declare var="hello world"
> > declare -n ref
> > ref=var
> > echo $ref
> > ref=var
> > echo $ref
> >
> > --- output ---
> > hello world
> > var

> Ah, LOL I think I need some sleep. This is not a bug. Sorry for all the noise.

For those trying to follow along, what's happening is the first time
"ref=var" is executed, ref becomes a reference to the variable var.
The second time "ref=var" is executed, ref is already a reference to a
variable, so the value "var" is assigned to the variable "var".

imadev:~$ declare -n ref=var1
imadev:~$ var1=old
imadev:~$ declare -p ref var1
declare -n ref="var1"
declare -- var1="old"
imadev:~$ ref=new
imadev:~$ declare -p ref var1
declare -n ref="var1"
declare -- var1="new"

Reply via email to