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/>.
14 # tests for miscellaneous builtins not tested elsewhere
18 ulimit -S -c 0 2>/dev/null
19 ulimit -c -S -- 1000 2>/dev/null
22 # check that break breaks loops
23 for i in a b c; do echo $i; break; echo bad-$i; done
25 for i in a b c; do echo $i; break 1; echo bad-$i; done
37 # check that break breaks nested loops
48 # check that continue continues loops
49 for i in a b c; do echo $i; continue; echo bad-$i ; done
51 for i in a b c; do echo $i; continue 1; echo bad-$i; done
63 # check that continue breaks out of nested loops
74 # check that `eval' re-evaluates arguments, but `builtin' and `command' do not
84 # test out eval with a temp environment
85 AVAR=bar eval echo \$AVAR
86 BVAR=xxx eval echo $AVAR
95 umask -S u=rwx,g=rwx,o=rx >/dev/null # 002
102 umask ${mask} # restore original mask
104 # builtin/command without arguments should do nothing. maybe someday they will
111 enable -aps ; enable -nps
114 case "$(type -t test)" in
115 builtin) echo oops -- enable -n test failed ;;
116 *) echo enable -n test worked ;;
120 case "$(type -t test)" in
121 builtin) echo enable test worked ;;
122 *) echo oops -- enable test failed ;;
125 # test options to exec
126 (exec -a specialname ${THIS_SH} -c 'echo $0' )
127 (exec -l -a specialname ${THIS_SH} -c 'echo $0' )
128 # test `clean' environment. if /bin/sh is bash, and the script version of
129 # printenv is run, there will be variables in the environment that bash
130 # sets on startup. Also test code that prefixes argv[0] with a dash.
131 (export FOO=BAR ; exec -c -l printenv ) | grep FOO
132 (FOO=BAR exec -c printenv ) | grep FOO
134 (export FOO=BAR ; exec printenv ) | grep FOO
135 (FOO=BAR exec printenv ) | grep FOO
137 # ok, forget everything about hashed commands
141 # this had better succeed, since command -p guarantees we will find the
147 # sourcing a zero-length-file had better not be an error
148 rm -f /tmp/zero-length-file
149 cp /dev/null /tmp/zero-length-file
150 . /tmp/zero-length-file
152 rm /tmp/zero-length-file
157 AVAR=foo . ./source1.sub
165 # make sure source with arguments does not change the shell's positional
166 # parameters, but that the sourced file sees the arguments as its
167 # positional parameters
169 . ./source3.sub x y z
172 # but if the sourced script sets the positional parameters explicitly, they
173 # should be reflected in the calling shell's positional parameters. this
174 # also tests one of the shopt options that controls source using $PATH to
181 # this is complicated when the sourced scripts gets its own positional
182 # parameters from arguments to `.'
188 # test out cd and $CDPATH
189 ${THIS_SH} ./builtins1.sub
191 # test behavior of `.' when given a non-existent file argument
192 ${THIS_SH} ./source5.sub
194 # test bugs in sourcing non-regular files, fixed post-bash-3.2
195 ${THIS_SH} ./source6.sub
197 # test bugs with source called from multiline aliases and other contexts
198 ${THIS_SH} ./source7.sub
200 # in posix mode, assignment statements preceding special builtins are
201 # reflected in the shell environment. `.' and `eval' need special-case
205 AVAR=foo . ./source1.sub
210 AVAR=foo eval echo \$AVAR
219 # but assignment statements preceding `export' are always reflected in
225 # assignment statements preceding `declare' should be displayed correctly,
226 # but not persist after the command
227 FOO='$$' declare -p FOO
231 # except for `declare -x', which should be equivalent to `export'
232 FOO='$$' declare -x FOO
236 # test out kill -l. bash versions prior to 2.01 did `kill -l num' wrong
237 sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
239 case "$(kill -l 1)" in
240 ${sigone/SIG/}) echo ok;;
241 *) echo oops -- kill -l failure;;
244 # kill -l and trap -l should display exactly the same output
245 sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
247 if [ "$sigone" != "$sigonea" ]; then
248 echo oops -- kill -l and trap -l differ
251 # POSIX.2 says that exit statuses > 128 are mapped to signal names by
252 # subtracting 128 so you can find out what signal killed a process
253 case "$(kill -l $(( 128 + 1)) )" in
254 ${sigone/SIG/}) echo ok;;
255 *) echo oops -- kill -l 129 failure;;
258 # out-of-range signal numbers should report the argument in the error
259 # message, not 128 less than the argument
262 # kill -l NAME should return the signal number
263 kill -l ${sigone/SIG/}
265 # test behavior of shopt xpg_echo
266 ${THIS_SH} ./builtins2.sub
268 # test behavior of declare -g
269 ${THIS_SH} ./builtins3.sub
271 # test behavior of using declare to create variables without assigning values
272 ${THIS_SH} ./builtins4.sub
274 # test behavior of set and unset array variables
275 ${THIS_SH} ./builtins5.sub
277 # test behavior of unset builtin with -f and -v options
278 ${THIS_SH} ./builtins6.sub
280 # test behavior of command builtin after changing it to a pseudo-keyword
281 ${THIS_SH} ./builtins7.sub
283 # this must be last -- it is a fatal error