bug-bash
[Top][All Lists]
Advanced

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

Re: Local variable can not unset within shell functions


From: Lawrence Velázquez
Subject: Re: Local variable can not unset within shell functions
Date: Thu, 11 Jul 2024 15:39:41 -0400
User-agent: Cyrus-JMAP/3.11.0-alpha0-568-g843fbadbe-fm-20240701.003-g843fbadb

On Thu, Jul 11, 2024, at 9:42 AM, Dr. Werner Fink wrote:
> I've a report that with later bash the following which works in bash-4.2
>
> [...]
>
>  linux-40cm:~ # x () {
>  >   local x=y
>  >   declare -p x
>  >   echo $x
>  >   unset x
>  >   declare -p x
>  >   echo $x
>  >  }
>  linux-40cm:~ # x
>  declare -- x="y"
>  y
>  -bash: declare: x: not found
> 
> but with bash-5.X the reporter sees (and complains)
>
>  sl15sp5:~ # x () {
>  >   local x=y
>  >   declare -p x
>  >   echo $x
>  >   unset x
>  >   declare -p x
>  >   echo $x
>  >  }
>  sl15sp5:~ # x
>  declare -- x="y"
>  y
>  declare -- x
>
> ... for global variables it works as expected.

I won't speculate about the issue, but your subject goes too far.
The variable really is unset here:

        % cat /tmp/x.bash
        x() {
                local x=y
                declare -p x
                echo "x is ${x-unset}"
                unset x
                declare -p x
                echo "x is ${x-unset}"
        }

        x
        % bash /tmp/x.bash
        declare -- x="y"
        x is y
        declare -- x
        x is unset

-- 
vq



reply via email to

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