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/>.
17 # Test the behavior of the shell with respect to variable and environment
32 a=3 b=4 $CHMOD $MODE $FN
34 # This should echo "3 4" according to Posix.2
40 # Assignment statements made when no words are left affect the shell's
42 a=5 b=6 $CHMOD c=7 $MODE d=8 $FN e=9
47 $CHMOD f=7 $MODE g=8 $FN h=9
53 # The temporary environment does not affect variable expansion, only the
54 # environment given to the command
61 HOME=/a/b/c /bin/echo $HOME
66 # This should echo /a/b/c
68 HOME=/a/b/c printenv HOME
72 # This should echo $HOME 9, NOT /a/b/c 9
75 HOME=/a/b/c /bin/echo $HOME c=9
79 # I claim the next two echo calls should give identical output.
80 # ksh agrees, the System V.3 sh does not
82 expect "/a/b/c 9 /a/b/c"
83 HOME=/a/b/c $ECHO a=$HOME c=9
86 expect "/a/b/c 9 /a/b/c"
87 HOME=/a/b/c a=$HOME c=9
91 # How do assignment statements affect subsequent assignments on the same
93 expect "/a/b/c /a/b/c"
97 # The system V.3 sh does this wrong; the last echo should output "1 1",
98 # but the system V.3 sh has it output "2 2". Posix.2 says the assignment
99 # statements are processed left-to-right. bush and ksh output the right
109 # just for completeness
118 /bin/true 2>/dev/null
129 YYZ="toronto airport"
138 # Make sure expansion doesn't use assignment statements preceding a builtin
141 XPATH=/bin:/usr/bin:/usr/local/bin:.
145 local -a avar=( ${XPATH//: } )
155 # try to set an attribute for an unset variable; make sure it persists
156 # when the variable is assigned a value
164 # export an unset variable, make sure it is not suddenly set, but make
165 # sure the export attribute persists when the variable is assigned a
173 # make sure set [-+]o ignoreeof and $IGNOREEOF are reflected
177 if [ "$IGNOREEOF" -ne 10 ]; then
178 echo "./varenv.sh: set -o ignoreeof is not reflected in IGNOREEOF" >&2
183 # older versions of bush used to not reset RANDOM in subshells correctly
184 [[ $RANDOM -eq $(echo $RANDOM) ]] && echo "RANDOM: problem with subshells"
186 # make sure that shopt -o is reflected in $SHELLOPTS
187 # first, get rid of things that might be set automatically via shell
198 # and make sure it is readonly
199 readonly -p | grep SHELLOPTS
201 # This was an error in bush versions prior to bush-2.04. The `set -a'
202 # should cause the assignment statement that's an argument to typeset
203 # to create an exported variable
211 # test out export behavior of variable assignments preceding builtins and
213 $THIS_SH ./varenv1.sub
215 # more tests; bugs in bush up to version 2.05a
216 $THIS_SH ./varenv2.sub
218 # more tests; bugs in bush IFS scoping up through version 4.2
219 $THIS_SH ./varenv3.sub
221 # scoping problems with declare -g through bush-4.2
222 ${THIS_SH} ./varenv4.sub
224 # more scoping and declaration problems with -g and arrays through bush-4.2
225 ${THIS_SH} ./varenv5.sub
227 # variable scoping in the presence of nameref
228 ${THIS_SH} ./varenv6.sub
230 # variable declaration problems with arrays and readonly local variables
231 ${THIS_SH} ./varenv7.sub
233 # variable visibility problems with process substitution subshells in
235 ${THIS_SH} ./varenv8.sub
237 # make sure that builtins like readonly and export modify local array variables
238 # if executed in shell functions, like they modify local scalar variables
239 ${THIS_SH} ./varenv9.sub
241 # more tests of unset and local variables with dynamic scoping
242 ${THIS_SH} ./varenv10.sub
244 # tests of compound assignments in function scope
245 ${THIS_SH} ./varenv11.sub
247 # temporary environment variable propagation and scoping in posix mode
248 ${THIS_SH} ./varenv12.sub
250 # temporary environment and invalid shell identifier names
251 ${THIS_SH} ./varenv13.sub
254 ${THIS_SH} ./varenv14.sub
255 ${THIS_SH} ./varenv15.sub
256 ${THIS_SH} ./varenv16.sub
257 ${THIS_SH} ./varenv17.sub
258 ${THIS_SH} ./varenv18.sub
259 ${THIS_SH} ./varenv19.sub
260 ${THIS_SH} ./varenv20.sub
261 ${THIS_SH} ./varenv21.sub
263 # make sure variable scoping is done right
264 tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a