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