mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix nested functions ignoring prefixed variable assignments (#37)
This commit fixes the bug described in att/ast#32. The fix and following explanation is from att/ast#467: While copying variables from function's local scope to a new scope, variable attributes were not copied. Such variables were not marked to be exported in the new function. For e.g. function f2 { env | grep -i "^foo"; } function f1 { env | grep -i "^foo"; f2; } foo=bar f1 prints 'foo=bar' only once, but it should print be twice. src/cmd/ksh93/sh/xec.c: - When variables from the local scope of a function are copied into the scope of a nested function, the attributes of the variables need to be copied as well. src/cmd/ksh93/tests/functions.sh: - Add regression tests from ksh2020 to check environment variables passed to functions.
This commit is contained in:
parent
e0b326ae15
commit
c1994b87f1
3 changed files with 15 additions and 0 deletions
|
@ -1258,5 +1258,13 @@ $SHELL -c 'PATH=/dev/null; fn() { unset -f fn; true; }; fn; fn' 2> /dev/null
|
|||
$SHELL -c 'PATH=/dev/null; function fn { unset -f fn; true; }; fn; fn' 2> /dev/null
|
||||
[[ $? != 127 ]] && err_exit 'unset of ksh function fails when it is still running'
|
||||
|
||||
# ======
|
||||
# Check if environment variables passed while invoking a function are exported
|
||||
# https://github.com/att/ast/issues/32
|
||||
unset foo
|
||||
function f2 { env | grep -q "^foo" || err_exit "Environment variable is not propogated from caller function"; }
|
||||
function f1 { f2; env | grep -q "^foo" || err_exit "Environment variable is not passed to a function"; }
|
||||
foo=bar f1
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue