File: execscript

package info (click to toggle)
bash 5.3-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 43,860 kB
  • sloc: ansic: 134,738; sh: 8,866; yacc: 5,966; makefile: 4,697; perl: 4,105; asm: 48; awk: 23; sed: 16
file content (209 lines) | stat: -rw-r--r-- 5,175 bytes parent folder | download
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
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

# this should succeed silently
$cmd &

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: $?
echo after exec1.sub: "$@"

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

notthere
echo $?

# now let's set up a command-not-found hook
command_not_found_handle()
{
        echo we would do something here with $1
}
notthere a b c
unset -f command_not_found_handle

# 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 $?

# trying to exec a directory is a fatal error
${THIS_SH} -c 'exec . ; default: after exec directory' bash
POSIXLY_CORRECT=1 ${THIS_SH} -c 'exec . ; posix: after exec directory' posix-bash

# even if preceded by `command'
${THIS_SH} -c 'command exec . ; default: after command exec directory 2' bash
POSIXLY_CORRECT=1 ${THIS_SH} -c 'command exec . ; posix: after command exec directory 2' posix-bash

# 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 > $TMPDIR/bashenv
export BASH_ENV=$TMPDIR/bashenv
${THIS_SH} ./exec3.sub
rm -f $TMPDIR/bashenv
unset BASH_ENV

# these results should be the same as with an empty PATH
PATH=.

notthere
echo $?
command notthere
echo $?
command -p notthere
echo $?

# 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 ${PWD}/exec8.sub

${THIS_SH} ./exec9.sub

${THIS_SH} ./exec10.sub
${THIS_SH} ./exec11.sub

true | `echo true` &

echo after

# Problem with bash at least back to version 3.0
${THIS_SH} -c 'VAR=0; VAR=1 command exec; exit ${VAR}'

# problem with bash through bash-4.1
(
        exec /var/empty/nosuch
        echo bad
) 2>/dev/null
[ $? = 127 ] || echo FAIL: bad exit status $? at $LINENO

unset FALSE
if [ -x /bin/false ]; then
	FALSE=/bin/false
elif [ -x /usr/bin/false ]; then
	FALSE=/usr/bin/false
else
	FALSE='command false'
fi

# problem with undoing redirections before running exit trap through bash-4.3

${THIS_SH} ./exec12.sub false	# function
${THIS_SH} ./exec12.sub command false
${THIS_SH} ./exec12.sub $FALSE

${THIS_SH} ./exec12.sub notfound
${THIS_SH} ./exec12.sub syntaxerror
${THIS_SH} ./exec12.sub nosuchcommand

# problem with fork optimization in bash-4.4-alpha

$THIS_SH -c 'echo a && /bin/echo b && echo c'
$THIS_SH -c 'echo A && /bin/echo B'

$THIS_SH -c '/bin/echo c && echo d'
$THIS_SH -c '/bin/echo c && /bin/echo d && echo e'

${THIS_SH} ./exec13.sub
${THIS_SH} ./exec14.sub

# problems with fork optimization in bash-5.2
${THIS_SH} ./exec15.sub

# problems with set -e and inverting commands' return status
${THIS_SH} ./exec16.sub

# test behavior of redirections when exec fails and does not exit the shell
${THIS_SH} ./exec17.sub