[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "unset var" pops var off variable stack instead of unsetting it
From: |
Stephane Chazelas |
Subject: |
Re: "unset var" pops var off variable stack instead of unsetting it |
Date: |
Sun, 19 Mar 2017 22:22:42 +0000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
2017-03-19 18:05:19 -0400, Chet Ramey:
> On 3/19/17 5:51 PM, Stephane Chazelas wrote:
>
> > On comp.unix.shell ot http://unix.stackexchange.com, I've posted
> > many articles describing how to do splitting in POSIX-like
> > shells:
> >
> > ( # subshell for local scope
> > unset -v IFS # restore default splitting behaviour
> > set -o noglob # disable globbing
> > cmd -- $var # split+glob with default IFS and glob disabled
> > )
> >
> > I'm now considering adding a note along the lines of:
> >
> > "Beware that with current versions of bash, pdksh and yash,
> > the above may not work if used in scripts that otherwise use
> > typeset/declare/local on $IFS or call a function with
> > `IFS=... my-function' (or IFS=... eval... or IFS=...
> > source...)"
>
> You can, of course, do whatever you want. You might want to read my
> message from yesterday about what happens when you do that, or look
> at the following examples, after which you may decide that the situation
> is not as dire.
>
> $ cat x2
> function foo
> {
> (
> unset -v IFS
> recho "${IFS-unset}"
> )
> }
>
> IFS=':|'
> foo
> echo after IFS = "$IFS"
> $ ../bash-4.4-patched/bash ./x2
> argv[1] = <unset>
> after IFS = :|
Yes, that one is fine but it is not the issue that is being
discussed here. There's no variable to pop off a stack above.
the issue is when that "foo" function is called in a context
where IFS had been declared locally. Like in:
IFS=1
function example {
typeset IFS=2
foo
}
Where "foo" would output "1", because then "unset -v IFS" would
*not* have unset IFS but instead would have restored the value
it had before the "typeset" (in that case, the global scope).
--
Stephane
- Re: "unset var" pops var off variable stack instead of unsetting it, (continued)
Re: "unset var" pops var off variable stack instead of unsetting it, Chet Ramey, 2017/03/18
Re: "unset var" pops var off variable stack instead of unsetting it, Chet Ramey, 2017/03/18
Re: "unset var" pops var off variable stack instead of unsetting it, Peter & Kelly Passchier, 2017/03/19
Re: "unset var" pops var off variable stack instead of unsetting it, 渡邊裕貴, 2017/03/20
Re: "unset var" pops var off variable stack instead of unsetting it, Stephane Chazelas, 2017/03/20
Re: "unset var" pops var off variable stack instead of unsetting it, Greg Wooledge, 2017/03/20