bug-bash
[Top][All Lists]
Advanced

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

Re: [BUG] Associative array initial reference name is made available in


From: Lawrence Velázquez
Subject: Re: [BUG] Associative array initial reference name is made available in another context
Date: Sat, 01 Jul 2023 16:37:13 -0400
User-agent: Cyrus-JMAP/3.9.0-alpha0-499-gf27bbf33e2-fm-20230619.001-gf27bbf33

On Sat, Jul 1, 2023, at 3:55 PM, Top Dawn wrote:
> I believe there is a bug with associative arrays, when once referenced in
> another function through the -n option, both the new reference name and the
> old one are made available.
>
> ```bash
>
> #!/bin/bash
> function my_function(){
>     declare -A my_array
>     my_array=(["one"]="one")
>     other_function "my_array"
> }
>
> function other_function(){
>     declare -n other_array="${1-}"
>     echo "${other_array["one"]}"
>     echo "${my_array["one"]}"
> }
>
> my_function
>
> ```
>
> will output :
>
> ```bash
>
> one
> one
>
> ```
>
> I believe this to be a bug.

What makes you think so?  Variables are always visible in invoked
functions, unless you shadow them using local/declare/typeset.

        % cat /tmp/foo.bash; echo
        function my_function(){
            declare -A my_array
            my_array=(["one"]="one")
            other_function
        }

        function other_function(){
            echo "${my_array["one"]}"
        }

        my_function

        % bash /tmp/foo.bash
        one

-- 
vq



reply via email to

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