Re: functions can fully unset local vars in other scopes

2022-08-01 Thread Chet Ramey
On 8/1/22 3:38 PM, Robert E. Griffith wrote: I just finished reading that 2018 discussion and the current discussion. Its hard for me to understand why this is an issue. kre's use case was    unset X    y=$X He called it 'braindead' for it to do anything expect to assign NULL/empty to Y but

Re: functions can fully unset local vars in other scopes

2022-08-01 Thread Robert E. Griffith
I just finished reading that 2018 discussion and the current discussion. Its hard for me to understand why this is an issue. kre's use case was unset X y=$X He called it 'braindead' for it to do anything expect to assign NULL/empty to Y but I think that is far from true. If he's thinking

Re: functions can fully unset local vars in other scopes

2022-08-01 Thread Chet Ramey
On 7/30/22 8:05 AM, Kerin Millar wrote: What consideration was given to creating “local --unset *VAR*” or “unset --local *VAR*” or some other equivalent that doesn't overload any existing command form? Obviously, only Chet can meaningfully respond to this. I mentioned the existence of the opt

Re: functions can fully unset local vars in other scopes

2022-07-30 Thread Kerin Millar
Hi Martin, On Sat, 30 Jul 2022 11:47:01 +1000 Martin D Kealey wrote: > On Fri, 29 Jul 2022 at 18:51, Kerin Millar wrote: > > > 5.0 added a localvar_unset option that impedes the behaviour of 'popping' > > from the outermost scope. I would have preferred for the sentence to have been quoted in

Re: functions can fully unset local vars in other scopes

2022-07-29 Thread Andreas Schwab
On Jul 30 2022, Martin D Kealey wrote: > *2: Adding a new global setting just adds yet another unreasonably > difficulty when sourcing files maintained by multiple authors into one > shell script program. It's not really different to the situation with perl or python. If you use a perl or python

Re: functions can fully unset local vars in other scopes

2022-07-29 Thread Martin D Kealey
On Fri, 29 Jul 2022 at 18:51, Kerin Millar wrote: > 5.0 added a localvar_unset option that impedes the behaviour of 'popping' > from the outermost scope. > > $ bash -c 'x=foo; f1() { local x=bar; f2; x=baz; }; f2() { unset x; > declare -p x; }; f1; declare -p x' > declare -- x="foo" > declare --

Re: functions can fully unset local vars in other scopes

2022-07-29 Thread Kerin Millar
Hi Emanuele, On Fri, 29 Jul 2022 03:59:07 +0200 Emanuele Torre wrote: > Description: > `bash' does not let `unset' fully undeclare local variables. (so that > they can be used later as `local' variables without needing to > redeclare them I assume.) > > bash-5.1$ x=abc; declare -p x

Re: functions can fully unset local vars in other scopes

2022-07-28 Thread Emanuele Torre
Thank you, Koichi and Greg. I didn't notice that this was intended and documented. Also it is good to know that `localvar_unset' exists. Cheers.

Re: functions can fully unset local vars in other scopes

2022-07-28 Thread Koichi Murase
2022年7月29日(金) 10:59 Emanuele Torre : > Description: > `bash' does not let `unset' fully undeclare local variables. (so that > they can be used later as `local' variables without needing to > redeclare them I assume.) > > [...] > > However, other functions are allowed to delete those v

Re: functions can fully unset local vars in other scopes

2022-07-28 Thread Greg Wooledge
On Fri, Jul 29, 2022 at 03:59:07AM +0200, Emanuele Torre wrote: > This enables defininng a "really_unset" function like so: > > really_unset () { unset "$@" ;} > > Which may be useful I guess. https://lists.gnu.org/archive/html/bug-bash/2010-05/msg00045.html https://fvue.nl/wiki/Bash:

Re: functions can fully unset local vars in other scopes

2022-07-28 Thread Emanuele Torre
> It may be nice to also add a "force" option for `unset' that makes it > actually unset the variable if it is `local'. Since this could be > useful in some cases and it won't be possible after the behaviour is > changed. Clarification I meant that it should fully undeclare local variables i