1 | ## compare_shells: bash
|
2 | ## oils_failures_allowed: 2
|
3 |
|
4 | #### SHELLOPTS is updated when options are changed
|
5 | echo $SHELLOPTS | grep -q xtrace
|
6 | echo $?
|
7 | set -x
|
8 | echo $SHELLOPTS | grep -q xtrace
|
9 | echo $?
|
10 | set +x
|
11 | echo $SHELLOPTS | grep -q xtrace
|
12 | echo $?
|
13 | ## STDOUT:
|
14 | 1
|
15 | 0
|
16 | 1
|
17 | ## END
|
18 | ## N-I dash/mksh STDOUT:
|
19 | 1
|
20 | 1
|
21 | 1
|
22 | ## END
|
23 |
|
24 | #### SHELLOPTS is readonly
|
25 | SHELLOPTS=x
|
26 | echo status=$?
|
27 | ## stdout: status=1
|
28 | ## N-I dash/mksh stdout: status=0
|
29 |
|
30 | # Setting a readonly variable in osh is a hard failure.
|
31 | ## OK osh status: 1
|
32 | ## OK osh stdout-json: ""
|
33 |
|
34 | #### SHELLOPTS and BASHOPTS are non-empty
|
35 |
|
36 | # 2024-06 - tickled by Samuel testing Gentoo
|
37 |
|
38 | if test -v SHELLOPTS; then
|
39 | echo 'shellopts is set'
|
40 | fi
|
41 | if test -v BASHOPTS; then
|
42 | echo 'bashopts is set'
|
43 | fi
|
44 |
|
45 | # bash: braceexpand:hashall etc.
|
46 |
|
47 | echo shellopts ${SHELLOPTS:?} > /dev/null
|
48 | echo bashopts ${BASHOPTS:?} > /dev/null
|
49 |
|
50 | ## STDOUT:
|
51 | shellopts is set
|
52 | bashopts is set
|
53 | ## END
|
54 |
|
55 | ## N-I dash status: 2
|
56 | ## N-I mksh status: 1
|
57 |
|
58 | #### SHELLOPTS reflects flags like sh -x
|
59 |
|
60 | $SH -x -c 'echo $SHELLOPTS' | grep -o xtrace
|
61 |
|
62 | ## STDOUT:
|
63 | xtrace
|
64 | ## END
|
65 |
|
66 | #### export SHELLOPTS does cross-process tracing
|
67 |
|
68 | $SH -c '
|
69 | export SHELLOPTS
|
70 | set -x
|
71 | echo 1
|
72 | $SH -c "echo 2"
|
73 | ' 2>&1 | sed 's/.*sh /sh /g'
|
74 |
|
75 | ## STDOUT:
|
76 | + echo 1
|
77 | 1
|
78 | sh -c 'echo 2'
|
79 | + echo 2
|
80 | 2
|
81 | ## END
|
82 |
|
83 | #### export SHELLOPTS does cross-process tracing with bash
|
84 |
|
85 | # calling bash
|
86 | $SH -c '
|
87 | export SHELLOPTS
|
88 | set -x
|
89 | #echo SHELLOPTS=$SHELLOPTS
|
90 | echo 1
|
91 | bash -c "echo 2"
|
92 | ' 2>&1 | sed 's/.*sh /sh /g'
|
93 |
|
94 | ## STDOUT:
|
95 | + echo 1
|
96 | 1
|
97 | sh -c 'echo 2'
|
98 | + echo 2
|
99 | 2
|
100 | ## END
|
101 |
|
102 | #### OSH calling bash with SHELLOPTS does not change braceexpand
|
103 |
|
104 | #echo outside=$SHELLOPTS
|
105 |
|
106 | # sed pattern to normalize spaces
|
107 | normalize='s/[ \t]\+/ /g'
|
108 |
|
109 | bash -c '
|
110 | #echo bash=$SHELLOPTS
|
111 | set -o | grep braceexpand | sed "$1"
|
112 | ' unused "$normalize"
|
113 |
|
114 | env SHELLOPTS= bash -c '
|
115 | #echo bash2=$SHELLOPTS
|
116 | set -o | grep braceexpand | sed "$1"
|
117 | ' unused "$normalize"
|
118 |
|
119 | ## STDOUT:
|
120 | braceexpand on
|
121 | braceexpand on
|
122 | ## END
|
123 |
|
124 | #### If shopt --set xtrace is allowed, it should update SHELLOPTS, not BASHOPTS
|
125 | case $SH in bash) exit ;; esac
|
126 |
|
127 | shopt --set xtrace
|
128 | echo SHELLOPTS=$SHELLOPTS
|
129 | set -x
|
130 | echo SHELLOPTS=$SHELLOPTS
|
131 | set +x
|
132 | echo SHELLOPTS=$SHELLOPTS
|
133 |
|
134 | ## STDOUT:
|
135 | SHELLOPTS=xtrace
|
136 | SHELLOPTS=xtrace
|
137 | SHELLOPTS=
|
138 | ## END
|
139 | ## N-I bash STDOUT:
|
140 | ## END
|
141 |
|
142 | #### shopt -s progcomp hostcomplete are stubs (bash-completion)
|
143 |
|
144 | shopt -s progcomp hostcomplete
|
145 | echo status=$?
|
146 |
|
147 | shopt -u progcomp hostcomplete
|
148 | echo status=$?
|
149 |
|
150 | ## STDOUT:
|
151 | status=0
|
152 | status=0
|
153 | ## END
|