diff --git a/NEWS b/NEWS index 0570f0dc6..6ad414e57 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed a bug that caused the kill and stop commands to segfault when given a non-existent job. +- Nested functions no longer ignore variable assignments that were prefixed + to their parent function, i.e. 'VAR=foo func' will now set $VAR to 'foo' + in the scope of any nested function 'func' runs. + 2020-06-20: - Fixed a bug that caused setting the following variables as readonly in diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c index 6bb4355eb..cfde49b29 100644 --- a/src/cmd/ksh93/sh/xec.c +++ b/src/cmd/ksh93/sh/xec.c @@ -3249,7 +3249,10 @@ static void local_exports(register Namval_t *np, void *data) if(nv_isarray(np)) nv_putsub(np,NIL(char*),0); if((cp = nv_getval(np)) && (mp = nv_search(nv_name(np), shp->var_tree, NV_ADD|HASH_NOSCOPE)) && nv_isnull(mp)) + { nv_putval(mp, cp, 0); + mp->nvflag = np->nvflag; + } } /* diff --git a/src/cmd/ksh93/tests/functions.sh b/src/cmd/ksh93/tests/functions.sh index ca51e026d..9ec50bd07 100755 --- a/src/cmd/ksh93/tests/functions.sh +++ b/src/cmd/ksh93/tests/functions.sh @@ -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))