1 # tests for miscellaneous builtins not tested elsewhere
5 ulimit -c 0 2>/dev/null
10 # this should return success, according to POSIX.2
15 # this had better return success, according to POSIX.2
19 # check that break breaks loops
20 for i in a b c; do echo $i; break; echo bad-$i; done
22 for i in a b c; do echo $i; break 1; echo bad-$i; done
34 # check that break breaks nested loops
45 # check that continue continues loops
46 for i in a b c; do echo $i; continue; echo bad-$i ; done
48 for i in a b c; do echo $i; continue 1; echo bad-$i; done
60 # check that continue breaks out of nested loops
71 # check that `eval' re-evaluates arguments, but `builtin' and `command' do not
81 # test out eval with a temp environment
82 AVAR=bar eval echo \$AVAR
83 BVAR=xxx eval echo $AVAR
92 umask -S u=rwx,g=rwx,o=rx >/dev/null # 002
99 umask ${mask} # restore original mask
101 # builtin/command without arguments should do nothing. maybe someday they will
108 enable -aps ; enable -nps
111 case "$(type -t test)" in
112 builtin) echo oops -- enable -n test failed ;;
113 *) echo enable -n test worked ;;
117 case "$(type -t test)" in
118 builtin) echo enable test worked ;;
119 *) echo oops -- enable test failed ;;
122 # test options to exec
123 (exec -a specialname ${THIS_SH} -c 'echo $0' )
124 (exec -l -a specialname ${THIS_SH} -c 'echo $0' )
125 # test `clean' environment. if /bin/sh is bash, and the script version of
126 # printenv is run, there will be variables in the environment that bash
127 # sets on startup. Also test code that prefixes argv[0] with a dash.
128 (export FOO=BAR ; exec -c -l printenv ) | grep FOO
129 (FOO=BAR exec -c printenv ) | grep FOO
131 (export FOO=BAR ; exec printenv ) | grep FOO
132 (FOO=BAR exec printenv ) | grep FOO
134 # ok, forget everything about hashed commands
138 # this had better succeed, since command -p guarantees we will find the
144 # sourcing a zero-length-file had better not be an error
145 rm -f /tmp/zero-length-file
146 cp /dev/null /tmp/zero-length-file
147 . /tmp/zero-length-file
149 rm /tmp/zero-length-file
154 AVAR=foo . ./source1.sub
162 # make sure source with arguments does not change the shell's positional
163 # parameters, but that the sourced file sees the arguments as its
164 # positional parameters
166 . ./source3.sub x y z
169 # but if the sourced script sets the positional parameters explicitly, they
170 # should be reflected in the calling shell's positional parameters. this
171 # also tests one of the shopt options that controls source using $PATH to
178 # this is complicated when the sourced scripts gets its own positional
179 # parameters from arguments to `.'
185 # test out cd and $CDPATH
186 ${THIS_SH} ./builtins.sub1
188 # test behavior of `.' when given a non-existant file argument
189 ${THIS_SH} ./source5.sub
191 # in posix mode, assignment statements preceding special builtins are
192 # reflected in the shell environment. `.' and `eval' need special-case
196 AVAR=foo . ./source1.sub
201 AVAR=foo eval echo \$AVAR
210 # but assignment statements preceding `export' are always reflected in
216 # assignment statements preceding `declare' should be displayed correctly,
217 # but not persist after the command
218 FOO='$$' declare -p FOO
222 # except for `declare -x', which should be equivalent to `export'
223 FOO='$$' declare -x FOO
227 # test out kill -l. bash versions prior to 2.01 did `kill -l num' wrong
228 sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
230 case "$(kill -l 1)" in
231 ${sigone/SIG/}) echo ok;;
232 *) echo oops -- kill -l failure;;
235 # kill -l and trap -l should display exactly the same output
236 sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
238 if [ "$sigone" != "$sigonea" ]; then
239 echo oops -- kill -l and trap -l differ
242 # POSIX.2 says that exit statuses > 128 are mapped to signal names by
243 # subtracting 128 so you can find out what signal killed a process
244 case "$(kill -l $(( 128 + 1)) )" in
245 ${sigone/SIG/}) echo ok;;
246 *) echo oops -- kill -l 129 failure;;
249 # out-of-range signal numbers should report the argument in the error
250 # message, not 128 less than the argument
253 # kill -l NAME should return the signal number
254 kill -l ${sigone/SIG/}
256 # this must be last -- it is a fatal error