On 20/03/2560 04:51, 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...)" >
Wouldn't it be better to avoid using a function like 'unset' (that works in the way you purport to expect) in a dynamically scoped language as a matter of principle?? If unset works like you would want/expect it, it would also discard all values of all higher scopes. Would it not be better to set IFS to the value desired (whatever default splitting behaviour you need)?? -- Peter