bug-bash
[Top][All Lists]
Advanced

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

Re: nameref in temp environment


From: Grisha Levit
Subject: Re: nameref in temp environment
Date: Fri, 20 May 2016 18:47:52 -0400

On Fri, May 20, 2016 at 3:05 PM, Chet Ramey <chet.ramey@case.edu> wrote:

It uses the existing variable for the readonly check and the
existing value to perform an append if desired.  I can see using the
nameref itself for both of those; what do you think?

I was thinking that desirable behavior is that something like var=foo printenv var should always print foo, no matter what attributes (other than readonly) are assigned to $var. This is based on the existing behavior, where stuff like subscript assignments, compound assignments, var’s -i/-u/-l flags, are all ignored in this context.

I think the issue of += is hard to handle consistently without considering the changes to export behavior Piotr and I were discussing earlier. Consider the cases below — I think it would be least surprising if they produced the same result.

declare -nx ref=var; var=foo; str=''
printenv ref                 # var
ref+=$str    printenv ref    # empty string...
ref+="$str"  printenv ref    # foo
ref=$ref$str printenv ref    # foo

If += were changed to use the name of the target variable, the last two cases would differ, which seems most strange.

BTW, perhaps exported (resolved) namerfs seem like a silly use case, but I think the idea could actually be really useful for legitimate shell stuff, like:

declare -nx DYLD_LIBRARY_PATH=LD_LIBRARY_PATH    # add Darwin compat
# existing *nix code here

I would propose that the following behavior would be least surprising for assignments before command names:


reply via email to

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