bug-bash
[Top][All Lists]
Advanced

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

Re: RFE: Please allow unicode ID chars in identifiers


From: Greg Wooledge
Subject: Re: RFE: Please allow unicode ID chars in identifiers
Date: Wed, 14 Jun 2017 08:43:14 -0400
User-agent: Mutt/1.4.2.3i

On Tue, Jun 13, 2017 at 04:58:59PM -0700, L A Walsh wrote:
> Forgive me if I'm misremembering, but hasn't Greg argued against
> the ability to supply "libraries" of re-usable scripts due to
> the ease with which names could conflict with each other and cause
> script incompatibilities?

Namespace collisions are certainly an issue, yes.  But my primary
argument against trying to write "libraries" in bash has always been
the limitations of bash's functions.

1) You can't return values from them (making them more like "commands"
   than actual functions).

2) You can't pass variables by reference.  Therefore:

3) You can't pass the name of a variable in which you'd like to receive
   a value from the function, to work around point 1.

4) You can't pass an array by name.  You have to pass every single array
   element separately, losing the indices in the process.

"declare -n" looks like it should address point 2, but it doesn't
do so safely.  It only works if you magically choose a name (within
the function) that the caller does NOT choose (outside the function).
In fact, the caller's variable name must not match ANY local variable
of the function, or it breaks.

See examples at <http://mywiki.wooledge.org/BashProgramming#Functions>.

If your function is recursive (is its own caller), then you're simply
doomed -- you can't avoid having the same name used in the caller and
callee, because they're both the same piece of code.  You might be able to
hack up a global indexed array of return values, and then each instance
of the recursive function can use its recursion depth as an index into
this array to retrieve its return value.  That's the best I can think of.



reply via email to

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