1 # tests for miscellaneous builtins not tested elsewhere
5 ulimit -c 0 2>/dev/null
7 # check that break breaks loops
8 for i in a b c; do echo $i; break; echo bad-$i; done
10 for i in a b c; do echo $i; break 1; echo bad-$i; done
22 # check that break breaks nested loops
33 # check that continue continues loops
34 for i in a b c; do echo $i; continue; echo bad-$i ; done
36 for i in a b c; do echo $i; continue 1; echo bad-$i; done
48 # check that continue breaks out of nested loops
59 # check that `eval' re-evaluates arguments, but `builtin' and `command' do not
69 # test out eval with a temp environment
70 AVAR=bar eval echo \$AVAR
71 BVAR=xxx eval echo $AVAR
80 umask -S u=rwx,g=rwx,o=rx >/dev/null # 002
87 umask ${mask} # restore original mask
89 # builtin/command without arguments should do nothing. maybe someday they will
96 enable -aps ; enable -nps
99 case "$(type -t test)" in
100 builtin) echo oops -- enable -n test failed ;;
101 *) echo enable -n test worked ;;
105 case "$(type -t test)" in
106 builtin) echo enable test worked ;;
107 *) echo oops -- enable test failed ;;
110 # test options to exec
111 (exec -a specialname ${THIS_SH} -c 'echo $0' )
112 (exec -l -a specialname ${THIS_SH} -c 'echo $0' )
113 # test `clean' environment. if /bin/sh is bash, and the script version of
114 # printenv is run, there will be variables in the environment that bash
115 # sets on startup. Also test code that prefixes argv[0] with a dash.
116 (export FOO=BAR ; exec -c -l printenv ) | grep FOO
117 (FOO=BAR exec -c printenv ) | grep FOO
119 (export FOO=BAR ; exec printenv ) | grep FOO
120 (FOO=BAR exec printenv ) | grep FOO
122 # ok, forget everything about hashed commands
126 # this had better succeed, since command -p guarantees we will find the
132 # sourcing a zero-length-file had better not be an error
133 rm -f /tmp/zero-length-file
134 cp /dev/null /tmp/zero-length-file
135 . /tmp/zero-length-file
137 rm /tmp/zero-length-file
142 AVAR=foo . ./source1.sub
150 # make sure source with arguments does not change the shell's positional
151 # parameters, but that the sourced file sees the arguments as its
152 # positional parameters
154 . ./source3.sub x y z
157 # but if the sourced script sets the positional parameters explicitly, they
158 # should be reflected in the calling shell's positional parameters. this
159 # also tests one of the shopt options that controls source using $PATH to
166 # this is complicated when the sourced scripts gets its own positional
167 # parameters from arguments to `.'
173 # test out cd and $CDPATH
174 ${THIS_SH} ./builtins1.sub
176 # test behavior of `.' when given a non-existant file argument
177 ${THIS_SH} ./source5.sub
179 # test bugs in sourcing non-regular files, fixed post-bash-3.2
180 ${THIS_SH} ./source6.sub
182 # in posix mode, assignment statements preceding special builtins are
183 # reflected in the shell environment. `.' and `eval' need special-case
187 AVAR=foo . ./source1.sub
192 AVAR=foo eval echo \$AVAR
201 # but assignment statements preceding `export' are always reflected in
207 # assignment statements preceding `declare' should be displayed correctly,
208 # but not persist after the command
209 FOO='$$' declare -p FOO
213 # except for `declare -x', which should be equivalent to `export'
214 FOO='$$' declare -x FOO
218 # test out kill -l. bash versions prior to 2.01 did `kill -l num' wrong
219 sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
221 case "$(kill -l 1)" in
222 ${sigone/SIG/}) echo ok;;
223 *) echo oops -- kill -l failure;;
226 # kill -l and trap -l should display exactly the same output
227 sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
229 if [ "$sigone" != "$sigonea" ]; then
230 echo oops -- kill -l and trap -l differ
233 # POSIX.2 says that exit statuses > 128 are mapped to signal names by
234 # subtracting 128 so you can find out what signal killed a process
235 case "$(kill -l $(( 128 + 1)) )" in
236 ${sigone/SIG/}) echo ok;;
237 *) echo oops -- kill -l 129 failure;;
240 # out-of-range signal numbers should report the argument in the error
241 # message, not 128 less than the argument
244 # kill -l NAME should return the signal number
245 kill -l ${sigone/SIG/}
247 # test behavior of shopt xpg_echo
248 ${THIS_SH} ./builtins2.sub
250 # test behavior of declare -g
251 ${THIS_SH} ./builtins3.sub
253 # this must be last -- it is a fatal error