]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/exec6.sub
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / exec6.sub
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.
5 #
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.
10 #
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/>.
13 #
14 # builtins with exit status inverted
15
16 ( true )
17 echo $?
18 ( ! true )
19 echo $?
20
21 ( false )
22 echo $?
23 ( ! false )
24 echo $?
25
26 # inverting shouldn't affect exit
27 (exit 42)
28 echo $?
29
30 ( ! exit 42 )
31 echo $?
32
33 # commands requiring an exec with exit status inverted -- broken in bash-2.04
34
35 ( ls > /dev/null 2>&1 )
36 echo $?
37 ( ! ls > /dev/null 2>&1 )
38 echo $?
39
40 touch /tmp/notwrite
41 chmod 400 /tmp/notwrite
42
43 # make sure redirection failures in commands whose exit status is inverted
44 # are handled correctly
45
46 ( ls > /tmp/notwrite ) 2>/dev/null
47 echo $?
48
49 ( ! ls > /tmp/notwrite ) 2>/dev/null
50 echo $?
51
52 # now add exit traps, true and false for commands with and without exit
53 # status inversion
54
55 (trap 'false' 0 ; ! ls > /tmp/notwrite ) 2>/dev/null
56 echo $?
57
58 (trap 'false' 0 ; ls > /tmp/notwrite ) 2>/dev/null
59 echo $?
60
61 (trap 'true' 0 ; ! ls > /tmp/notwrite ) 2>/dev/null
62 echo $?
63
64 (trap 'true' 0 ; ls > /tmp/notwrite ) 2>/dev/null
65 echo $?
66
67 rm -f /tmp/notwrite