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: alex xmb sw ratchev
Subject: Re: Local variable can not unset within shell functions
Date: Thu, 11 Jul 2024 16:34:35 +0200

On Thu, Jul 11, 2024, 15:42 Dr. Werner Fink <werner@suse.de> wrote:

> Hi,
>
> I've a report that with later bash the following which works in bash-4.2
>
>  x () {
>   local x=y
>   declare -p x
>   echo $x
>   unset x
>   declare -p x
>   echo $x
>  }
>
> with
>
>  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
>

id aay the v5 is more valid as error got replaced by working code ( var=foo
; sav=$( declare -p var ) ; .. ; eval "$var" ( or maybe another noeval
version )

greets

... for global variables it works as expected.
>
> Werner
>
> --
>   "Having a smoking section in a restaurant is like having
>           a peeing section in a swimming pool." -- Edward Burr
>


reply via email to

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