1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 fn() { foo=abc : ; typeset +x foo; printenv|grep ^foo=; }
24 var=2 : # or 'var=2 return', or another special builtin
26 echo $FUNCNAME: var = $var
30 unset -v var # bug: fails silently
33 echo ${var+"BUG: still set 1"}
37 echo ${var+"BUG: still set 2"}
42 fn() { foo=abc : ; typeset +x foo; echo -n 'inside: ' ; declare -p foo; }
52 var=value declare -x var
53 echo -n 'inside: ' ; declare -p var
58 echo -n 'outside: ' ; declare -p var
63 # this will probably change behavior; export shouldn't behave like this when
64 # not in posix mode and the sequencing is probably wrong in posix mode. since
65 # export is a special builtin, the variable assignment should modify the
66 # local variable, as if a standalone assignment statement had been executed
67 # (posix modifying "the current execution environment") leaving the global
68 # variable unchanged. all shells, including bash, modify the local variable;
69 # bash was the only one that propagates the value out to the calling
70 # environment, but no longer does so.
76 echo -n 'inside: ' ; declare -p var
81 echo -n 'outside: ' ; declare -p var
90 echo -n 'inside: ' ; declare -p var
95 echo -n 'outside: ' ; declare -p var
102 echo -n 'inside func: ' ; echo "var=${var-<unset>}"
107 echo -n 'outside 1.0: ' ; echo "var=${var-<unset>}"
111 echo -n 'outside 1.1: ' ; echo "var=${var-<unset>}"
116 echo -n 'outside 2.0: ' ; echo "var=${var-<unset>}"
119 echo -n 'outside 2.1: ' ; echo "var=${var-<unset>}"
127 echo -n 'inside func1: ' ; echo "var=${var-<unset>}"
132 echo -n 'outside 3.0: ' ; echo "var=${var-<unset>}"
141 echo -n 'inside func2: ' ; echo "var=${var-<unset>}"
146 echo -n 'outside 4.0: ' ; echo "var=${var-<unset>}"
149 unset -f fecho foo bar
156 local var="foo: bye bye"
157 var="foo: hello world" fecho
161 var="bar: hello world" fecho
166 echo after foo: var=$var
169 echo after bar: var=$var