summaryrefslogtreecommitdiff
path: root/tests/execscript
blob: 3629c57a90899b2ee10cbe8ae03b2fab9a06dade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
export LC_ALL=C
export LANG=C

if [ $UID -eq 0 ]; then
        echo "execscript: the test suite should not be run as root" >&2
fi

set -- one two three
echo before exec1.sub: "$@"
echo calling exec1.sub
./exec1.sub aa bb cc dd ee
echo after exec1.sub with args: $?
./exec1.sub
echo after exec1.sub without args: $?

# set up a fixed path so we know notthere will not be found
PATH=/usr/bin:/bin:/usr/local/bin:
export PATH

notthere
echo $?

# this is iffy, since the error messages may vary from system to system
# and /tmp might not exist
ln -s ${THIS_SH} /tmp/bash 2>/dev/null
if [ -f /tmp/bash ]; then
	/tmp/bash notthere
else
	${THIS_SH} notthere
fi
echo $?
rm -f /tmp/bash

# /bin/sh should be there on all systems
${THIS_SH} /bin/sh
echo $?

# try executing a directory
/
echo $?

${THIS_SH} /
echo $?

# try sourcing a directory
. /
echo $?

# try sourcing a binary file -- post-2.04 versions don't do the binary file
# check, and will probably fail with `command not found', or status 127
# bash-4.1 and later check for 256 NUL characters and fail as binary files
# if there are more than that, it's probably binary
. ${THIS_SH} 2>/dev/null
echo $?

# post-bash-2.05 versions allow sourcing non-regular files
. /dev/null
echo $?

# kill two birds with one test -- test out the BASH_ENV code
echo echo this is bashenv > /tmp/bashenv
export BASH_ENV=/tmp/bashenv
${THIS_SH} ./exec3.sub
rm -f /tmp/bashenv
unset BASH_ENV

# we're resetting the $PATH to empty, so this should be last
PATH=

notthere
echo $?

command notthere
echo $?

command -p notthere
echo $?

# but -p should guarantee that we find all the standard utilities, even
# with an empty or unset $PATH
command -p sh -c 'echo this is $0'
unset PATH
command -p sh -c 'echo this is $0'

# a bug in bash before bash-2.01 caused PATH to be set to the empty string
# when command -p was run with PATH unset
echo ${PATH-unset}

echo "echo ok" | ${THIS_SH} -t

${THIS_SH} ./exec2.sub
echo $?

${THIS_SH} ./exec4.sub

# try exec'ing a command that cannot be found in $PATH
${THIS_SH} ./exec5.sub

# this was a bug in bash versions before bash-2.04
${THIS_SH} -c 'cat </dev/null | cat >/dev/null' >&-

# checks for proper return values in subshell commands with inverted return
# values

${THIS_SH} ./exec6.sub

# checks for properly deciding what constitutes an executable file
${THIS_SH} ./exec7.sub

${THIS_SH} -i ./exec8.sub

true | `echo true` &

echo after