4 # Test the behavior of the shell with respect to variable and environment
19 a=3 b=4 $CHMOD $MODE $FN
21 # This should echo "3 4" according to Posix.2
27 # Assignment statements made when no words are left affect the shell's
29 a=5 b=6 $CHMOD c=7 $MODE d=8 $FN e=9
34 $CHMOD f=7 $MODE g=8 $FN h=9
40 # The temporary environment does not affect variable expansion, only the
41 # environment given to the command
48 HOME=/a/b/c /bin/echo $HOME
53 # This should echo /a/b/c
55 HOME=/a/b/c printenv HOME
59 # This should echo $HOME 9, NOT /a/b/c 9
62 HOME=/a/b/c /bin/echo $HOME c=9
66 # I claim the next two echo calls should give identical output.
67 # ksh agrees, the System V.3 sh does not
69 expect "/a/b/c 9 /a/b/c"
70 HOME=/a/b/c $ECHO a=$HOME c=9
73 expect "/a/b/c 9 /a/b/c"
74 HOME=/a/b/c a=$HOME c=9
78 # How do assignment statements affect subsequent assignments on the same
80 expect "/a/b/c /a/b/c"
84 # The system V.3 sh does this wrong; the last echo should output "1 1",
85 # but the system V.3 sh has it output "2 2". Posix.2 says the assignment
86 # statements are processed left-to-right. bash and ksh output the right
96 # just for completeness
105 /bin/true 2>/dev/null
116 YYZ="toronto airport"
125 # Make sure expansion doesn't use assignment statements preceding a builtin
128 XPATH=/bin:/usr/bin:/usr/local/bin:.
132 local -a avar=( ${XPATH//: } )
142 # try to set an attribute for an unset variable; make sure it persists
143 # when the variable is assigned a value
151 # export an unset variable, make sure it is not suddenly set, but make
152 # sure the export attribute persists when the variable is assigned a
160 # make sure set [-+]o ignoreeof and $IGNOREEOF are reflected
164 if [ "$IGNOREEOF" -ne 10 ]; then
165 echo "./varenv.sh: set -o ignoreeof is not reflected in IGNOREEOF" >&2
170 # older versions of bash used to not reset RANDOM in subshells correctly
171 [[ $RANDOM -eq $(echo $RANDOM) ]] && echo "RANDOM: problem with subshells"
173 # make sure that shopt -o is reflected in $SHELLOPTS
174 # first, get rid of things that might be set automatically via shell
185 # and make sure it is readonly
186 readonly -p | grep SHELLOPTS
188 # This was an error in bash versions prior to bash-2.04. The `set -a'
189 # should cause the assignment statement that's an argument to typeset
190 # to create an exported variable
198 # test out export behavior of variable assignments preceding builtins and
200 $THIS_SH ./varenv1.sub
202 # more tests; bugs in bash up to version 2.05a
203 $THIS_SH ./varenv2.sub
205 # make sure variable scoping is done right
206 tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a