bug-bash
[Top][All Lists]
Advanced

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

Re: RFE: Fix the name collision issues and typing issues with namerefs,


From: Greg Wooledge
Subject: Re: RFE: Fix the name collision issues and typing issues with namerefs, improve various issues for function libraries
Date: Wed, 14 Jun 2017 12:18:15 -0400
User-agent: Mutt/1.4.2.3i

On Wed, Jun 14, 2017 at 12:04:35PM -0400, tetsujin@scope-eye.net wrote:
> So first off, the circular reference problem with "declare -n"
> apparently doesn't exist in Korn Shell: If you "typeset -n x=$1", and
> $1 is "x", it's not a circular reference.

Korn shell actually has two different *kinds* of functions.

If you declare using:  foo() { ...; }

Then you get bash-like behavior.

If you declare using:  function foo { ...; }

Then it works as you described.

$ ksh
$ foo() { typeset -n x="$1"; x=y; }
$ x=global
$ foo x
ksh: typeset: x: invalid self reference
$ function bar { typeset -n x="$1"; x=y; }
$ bar x
$ echo "$x"
y

As far as I know, bash has no equivalent of ksh's "function foo"
declaration.  Bash permits that *syntax* to be used as a function
declaration, but it has exactly the same semantics as "foo()".

> Regarding return values, there's a couple ways of looking at this:
> [...]

You're retracing a lot of the ground I've already covered in the last
few years.  Which is cool, and I'll be happy if you find something
that I missed.



reply via email to

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