From 1d5cace9db9aef76f26b2d7ba54bbb76443b00b2 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 20:33:23 +0200 Subject: Adding upstream version 5.0. Signed-off-by: Daniel Baumann --- tests/varenv12.sub | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/varenv12.sub (limited to 'tests/varenv12.sub') diff --git a/tests/varenv12.sub b/tests/varenv12.sub new file mode 100644 index 0000000..edba3c9 --- /dev/null +++ b/tests/varenv12.sub @@ -0,0 +1,100 @@ +set -o posix + +fn() { foo=abc : ; typeset +x foo; printenv|grep ^foo=; } + +fn +unset -v foo +unset -f fn + +func1() { + var=1 + var=2 : # or 'var=2 return', or another special builtin + unset -v var + echo $FUNCNAME: var = $var +} +func2() { + func1 + unset -v var # bug: fails silently +} +func1 +echo ${var+"BUG: still set 1"} + +unset var +func2 +echo ${var+"BUG: still set 2"} + +unset -v var +unset -f func1 func2 + +fn() { foo=abc : ; typeset +x foo; echo -n 'inside: ' ; declare -p foo; } +fn +echo outside: +declare -p foo + +unset -v foo +unset -f fn + +func() +{ + var=value declare -x var + echo -n 'inside: ' ; declare -p var +} + +var=one +func +echo -n 'outside: ' ; declare -p var + +unset -v var +unset -f func + +# this will probably change behavior; export shouldn't behave like this when +# not in posix mode and the sequencing is probably wrong in posix mode. since +# export is a special builtin, the variable assignment should modify the +# global variable, leaving the local variable unchanged. all shells, including +# bash, modify the local variable; bash is the only one that propagates the +# value out to the calling environment. bash does that only when in posix +# mode. + +func() +{ + local var=inside + var=value export var + echo -n 'inside: ' ; declare -p var +} + +var=outside +func +echo -n 'outside: ' ; declare -p var + +unset -v var +unset -f func + +func() +{ + local var=local + var=global : + echo -n 'inside: ' ; declare -p var +} + +var=outside +func +echo -n 'outside: ' ; declare -p var + +unset -v var +unset -f func + +# test whether or not temporary environment assignments are exported +# in posix mode +showfoo() +{ + printf %s "foo=${foo-}" + echo -n ' environment foo=' + printenv foo || echo +} +unset foo +showfoo +foo=foo showfoo +showfoo + +unset -v foo +unset -f showfoo -- cgit v1.2.3