mainThe GNU Bourne-Again SHell - Support: sr #109669, -a option of local prevents using...

 
 

sr #109669: -a option of local prevents using previous value

Submitter:  Kevin Locke <kevinoid>
Submitted:  Mon 08 Apr 2019 12:08:32 AM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  Done
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 06 May 2020 02:47:27 PM UTC, comment #5: 

There is a fix for this in the latest devel branch push.

Chet Ramey <chet>
Group administrator
Mon 27 Apr 2020 08:36:12 PM UTC, comment #4: 

Bummer.  No worries.  Thanks for the update!

Kevin Locke <kevinoid>
Mon 27 Apr 2020 08:08:50 PM UTC, comment #3: 

I took this change out; it had some undesirable side effects. I'm not sure when it will be fixed.

Chet Ramey <chet>
Group administrator
Tue 17 Mar 2020 11:00:10 PM UTC, comment #2: 

Sounds great.  Thanks for investigating and working on it!

Kevin Locke <kevinoid>
Tue 17 Mar 2020 10:55:59 PM UTC, comment #1: 

It's a combination of using exactly local -a and compound variable assignment. There will be a fix in the next devel branch push, and possibly further changes in a subsequent major bash release.

Chet Ramey <chet>
Group administrator
Mon 08 Apr 2019 12:08:32 AM UTC, original submission:  

It is possible to initialize a local array variable with the value being shadowed if the -a option is not specified.  On Bash 4.3 and later, if -a is specified, the value will be empty or cause an unbound variable error for indirect references.  For example:


arr=(zero one two)
shadow_arr() {
    local arr=("${arr[@]}")
    echo "${arr[@]}"
}
shadow_arr


Prints "zero one two" in all versions of Bash.


arr=(zero one two)
shadow_arr() {
    local -a arr=("${arr[@]}")
    echo "${arr[@]}"
}
shadow_arr


Prints "zero one two" before Bash 4.3 and "" in Bash 4.3 and later.


set -u
arr=(zero one two)
name='arr[@]'
shadow_arr() {
    local -a arr=("${!name}")
    echo "${arr[@]}"
}
shadow_arr


Prints "zero one two" before Bash 4.3 and fails with "./example.bash: line 5: !name: unbound variable" in Bash 4.3 and later.

I bisected the change in behavior to commit ac50fbac.

Thanks for considering,
Kevin

Related Stack Overflow question:  https://stackoverflow.com/q/29309833

Kevin Locke <kevinoid>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by kevinoid (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-03-17 chet StatusNone Done

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code