Inconsistency in the handling of variables inside a function when using
From:
Eduardo A . Bustamante López
Subject:
Inconsistency in the handling of variables inside a function when using a tempenv variable
Date:
Thu, 22 Oct 2015 17:34:49 -0500
User-agent:
Mutt/1.5.23 (2014-03-12)
I found this some time ago, but didn't report it because I couldn't come up
with a patch:
dualbus@hp ~ % for sh in bash mksh zsh ksh93 dash; do $sh -c
't=${KSH_VERSION+typeset}; f() { x=3; ${t:-local} x; echo $x; }; [ "$(f)" =
"$(x=4 f)" ]'; echo $sh $?; done
bash 1
mksh 0
zsh 0
ksh93 0
dash 0
dualbus@hp ~ % bash -xc 'f() { x=3; local x; echo $x; }; f; x=4 f'
+ f
+ x=3
+ local x
+ echo
+ x=4
+ f
+ x=3
+ local x
+ echo 3
3
I'm putting it here so I don't forget about it.
Bash is the only one that handles this: tmpenv - global - local variable chain
in that way.
--
Eduardo Bustamante
https://dualbus.me/