]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/execscript
Bash-4.2 distribution sources and documentation
[thirdparty/bash.git] / tests / execscript
CommitLineData
d166f048
JA
1export LC_ALL=C
2export LANG=C
3
b80f6443 4if [ $UID -eq 0 ]; then
f73dda09
JA
5 echo "execscript: the test suite should not be run as root" >&2
6fi
7
d166f048 8set -- one two three
cce855bc
JA
9echo before exec1.sub: "$@"
10echo calling exec1.sub
11./exec1.sub aa bb cc dd ee
12echo after exec1.sub with args: $?
13./exec1.sub
14echo after exec1.sub without args: $?
d166f048
JA
15
16# set up a fixed path so we know notthere will not be found
17PATH=/usr/bin:/bin:/usr/local/bin:
18export PATH
19
20notthere
21echo $?
22
23# this is iffy, since the error messages may vary from system to system
b80f6443
JA
24# and /tmp might not exist
25ln -s ${THIS_SH} /tmp/bash 2>/dev/null
26if [ -f /tmp/bash ]; then
27 /tmp/bash notthere
28else
29 ${THIS_SH} notthere
30fi
d166f048 31echo $?
b80f6443 32rm -f /tmp/bash
d166f048
JA
33
34# /bin/sh should be there on all systems
35${THIS_SH} /bin/sh
36echo $?
37
38# try executing a directory
39/
40echo $?
41
42${THIS_SH} /
43echo $?
44
45# try sourcing a directory
46. /
47echo $?
48
28ef6c31
JA
49# try sourcing a binary file -- post-2.04 versions don't do the binary file
50# check, and will probably fail with `command not found', or status 127
0001803f
CR
51# bash-4.1 and later check for 256 NUL characters and fail as binary files
52# if there are more than that, it's probably binary
d166f048
JA
53. ${THIS_SH} 2>/dev/null
54echo $?
55
f73dda09 56# post-bash-2.05 versions allow sourcing non-regular files
d166f048
JA
57. /dev/null
58echo $?
59
60# kill two birds with one test -- test out the BASH_ENV code
61echo echo this is bashenv > /tmp/bashenv
62export BASH_ENV=/tmp/bashenv
cce855bc 63${THIS_SH} ./exec3.sub
d166f048
JA
64rm -f /tmp/bashenv
65unset BASH_ENV
66
67# we're resetting the $PATH to empty, so this should be last
68PATH=
69
70notthere
71echo $?
72
73command notthere
74echo $?
75
76command -p notthere
77echo $?
78
79# but -p should guarantee that we find all the standard utilities, even
80# with an empty or unset $PATH
81command -p sh -c 'echo this is $0'
82unset PATH
83command -p sh -c 'echo this is $0'
84
85# a bug in bash before bash-2.01 caused PATH to be set to the empty string
86# when command -p was run with PATH unset
87echo ${PATH-unset}
88
89echo "echo ok" | ${THIS_SH} -t
90
cce855bc 91${THIS_SH} ./exec2.sub
d166f048
JA
92echo $?
93
cce855bc
JA
94${THIS_SH} ./exec4.sub
95
96# try exec'ing a command that cannot be found in $PATH
97${THIS_SH} ./exec5.sub
bb70624e
JA
98
99# this was a bug in bash versions before bash-2.04
100${THIS_SH} -c 'cat </dev/null | cat >/dev/null' >&-
28ef6c31
JA
101
102# checks for proper return values in subshell commands with inverted return
103# values
104
105${THIS_SH} ./exec6.sub
b80f6443
JA
106
107# checks for properly deciding what constitutes an executable file
108${THIS_SH} ./exec7.sub
95732b49 109
3185942a
JA
110${THIS_SH} -i ./exec8.sub
111
495aee44
CR
112${THIS_SH} ./exec9.sub
113
95732b49
JA
114true | `echo true` &
115
116echo after
495aee44
CR
117
118# Problem with bash at least back to version 3.0
119${THIS_SH} -c 'VAR=0; VAR=1 command exec; exit ${VAR}'
120
121# problem with bash through bash-4.1
122(
123 exec /var/empty/nosuch
124 echo bad
125) 2>/dev/null
126[ $? = 127 ] || echo FAIL: bad exit status $? at $LINENO