Re: unset does not act as expected on namerefs

2015-06-06 Thread Chet Ramey
On 6/2/15 11:37 AM, Greg Wooledge wrote: > Ksh's nameref is completely different. With one of ksh's two different > kinds of functions, you actually CAN use ksh nameref to pass a value > back to the caller without variable name collisions. In my opinion, the most interesting thing about ksh93's

Re: unset does not act as expected on namerefs

2015-06-06 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 6/1/15 9:59 PM, Shawn Wilson wrote: > Top posting as I'm kinda going out of band of the thread here; > > Having read the discussion, I guess the issue I brought up really > isn't a "bug" (though Greg's points probably should be considered > bugs).

Re: unset does not act as expected on namerefs

2015-06-06 Thread Dan Douglas
On Tue, Jun 2, 2015 at 7:31 AM, Greg Wooledge wrote: > There's declare -i, but no sane person USES that, so we can ignore it. While in bash `-i` likely either has no effect or slows things down very slightly, in ksh93 and probably zsh it's a huge performance win because it prevents integers and f

Re: unset does not act as expected on namerefs

2015-06-02 Thread Shawn Wilson
On +2015/06/02 08:31:57, Greg Wooledge wrote: > > > Also, whatever happens, I think there should also be a way to test > > for variable type (either another test flag or something like perl's > > ref() ). > > Bash is not a strongly typed language. You've got strings, and indexed > arrays, and a

Re: unset does not act as expected on namerefs

2015-06-02 Thread Greg Wooledge
On Tue, Jun 02, 2015 at 11:16:27AM -0400, Shawn Wilson wrote: > I would argue that a nameref is a variable type. I suppose you're right, insofar as it has its own special rules that you have to know about. A lot of people wanted declare -n to be more than it is. It's really just syntactic sugar

Re: unset does not act as expected on namerefs

2015-06-02 Thread Greg Wooledge
On Mon, Jun 01, 2015 at 09:59:51PM -0400, Shawn Wilson wrote: > I'll preface this by saying I'm not an expert in bash by any > means. However, most languages have a garbage collection facility C does not. Bash (all shells, really) is very strongly influenced by C. > and most > high level languag

Re: unset does not act as expected on namerefs

2015-06-01 Thread Shawn Wilson
Top posting as I'm kinda going out of band of the thread here; Having read the discussion, I guess the issue I brought up really isn't a "bug" (though Greg's points probably should be considered bugs). I'll preface this by saying I'm not an expert in bash by any means. However, most languages have

Re: unset does not act as expected on namerefs

2015-05-29 Thread Chet Ramey
On 5/27/15 8:25 AM, Greg Wooledge wrote: > 1) It doesn't cross scopes. It's not like Tcl's upvar at all. It > only refers to a variable in the same scope (which, following the > standard bash rules, means it'll recursively search upward until > it finds a matching variable by name).

Re: unset does not act as expected on namerefs

2015-05-27 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 5/26/15 5:02 PM, Shawn Wilson wrote: > On +2015/05/26 18:05:18, Geir Hauge wrote: >> On Tue, May 26, 2015 at 11:00:45AM -0500, Eduardo A. Bustamante López wr ote: >>> # Here we 'unset ref', which actually unsets 'var'. Then, we assign 'va r' to >>>

Re: unset does not act as expected on namerefs

2015-05-27 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 5/26/15 10:31 AM, 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:~/

Re: unset does not act as expected on namerefs

2015-05-27 Thread Greg Wooledge
On Tue, May 26, 2015 at 05:02:43PM -0400, Shawn Wilson wrote: > If there's no good reason to keep this as is (some use case where > this might be wanted and breaking backward compatibility - I can't > see anyone actually *wanting* it this way) shouldn't it be changed? > A behavior can be documented

Re: unset does not act as expected on namerefs

2015-05-26 Thread Shawn Wilson
On +2015/05/26 18:05:18, Geir Hauge wrote: > On Tue, May 26, 2015 at 11:00:45AM -0500, Eduardo A. Bustamante López wrote: > > # 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'. > > dua

Re: unset does not act as expected on namerefs

2015-05-26 Thread Geir Hauge
On Tue, May 26, 2015 at 11:00:45AM -0500, Eduardo A. Bustamante López wrote: > # 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 -

Re: unset does not act as expected on namerefs

2015-05-26 Thread Eduardo A . Bustamante López
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=va

Re: unset does not act as expected on namerefs

2015-05-26 Thread Geir Hauge
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@s

Re: unset does not act as expected on namerefs

2015-05-26 Thread Shawn Wilson
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:~/t

Re: unset does not act as expected on namerefs

2015-05-26 Thread Greg Wooledge
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) > swi