1
1
# # compare_shells: bash dash mksh zsh
2
+ # # oils_failures_allowed: 1
2
3
3
4
# ### can continue after unknown option
4
5
#
@@ -22,7 +23,6 @@ echo done
22
23
# # stdout: a b c
23
24
# # status: 1
24
25
25
-
26
26
# ### nounset with "$@"
27
27
set a b c
28
28
set -u # shouldn't touch argv
@@ -63,6 +63,56 @@ echo status=$?
63
63
# # status: 1
64
64
# # OK dash status: 2
65
65
66
+ # ### set -o lists options
67
+ # NOTE: osh doesn't use the same format yet.
68
+ set -o | grep -o noexec
69
+ # # STDOUT:
70
+ noexec
71
+ # # END
72
+
73
+ # ### 'set' and 'eval' round trip
74
+
75
+ # NOTE: not testing arrays and associative arrays!
76
+ _space=' [ ]'
77
+ _whitespace=$' [\t\r\n ]'
78
+ _sq=" 'single quotes'"
79
+ _backslash_dq=" \\ \" "
80
+ _unicode=$' [\u03bc]'
81
+
82
+ # Save the variables
83
+ varfile=$TMP /vars-$( basename $SH ) .txt
84
+
85
+ set | grep ' ^_' > " $varfile "
86
+
87
+ # Unset variables
88
+ unset _space _whitespace _sq _backslash_dq _unicode
89
+ echo [ $_space $_whitespace $_sq $_backslash_dq $_unicode ]
90
+
91
+ # Restore them
92
+
93
+ . $varfile
94
+ echo " Code saved to $varfile " 1>&2 # for debugging
95
+
96
+ test " $_space " = ' [ ]' && echo OK
97
+ test " $_whitespace " = $' [\t\r\n ]' && echo OK
98
+ test " $_sq " = " 'single quotes'" && echo OK
99
+ test " $_backslash_dq " = " \\ \" " && echo OK
100
+ test " $_unicode " = $' [\u03bc]' && echo OK
101
+
102
+ # # STDOUT:
103
+ [ ]
104
+ OK
105
+ OK
106
+ OK
107
+ OK
108
+ OK
109
+ # # END
110
+
111
+ # # BUG zsh status: 1
112
+ # # BUG zsh STDOUT:
113
+ [ ]
114
+ # # END
115
+ #
66
116
# ### set - -
67
117
set a b
68
118
echo " $@ "
@@ -117,52 +167,46 @@ a b
117
167
--
118
168
# # END
119
169
120
- # ### set -o lists options
121
- # NOTE: osh doesn't use the same format yet.
122
- set -o | grep -o noexec
123
- # # STDOUT:
124
- noexec
125
- # # END
126
-
127
- # ### 'set' and 'eval' round trip
128
-
129
- # NOTE: not testing arrays and associative arrays!
130
- _space=' [ ]'
131
- _whitespace=$' [\t\r\n ]'
132
- _sq=" 'single quotes'"
133
- _backslash_dq=" \\ \" "
134
- _unicode=$' [\u03bc]'
170
+ # ### set - leading single dash is ignored, turns off xtrace verbose (#2364)
135
171
136
- # Save the variables
137
- varfile=$TMP /vars-$( basename $SH ) .txt
172
+ show_options () {
173
+ case $- in
174
+ * v* ) echo verbose-on ;;
175
+ esac
176
+ case $- in
177
+ * x* ) echo xtrace-on ;;
178
+ esac
179
+ }
138
180
139
- set | grep ' ^_' > " $varfile "
181
+ set -x -v
182
+ show_options
183
+ echo
140
184
141
- # Unset variables
142
- unset _space _whitespace _sq _backslash_dq _unicode
143
- echo [ $_space $_whitespace $_sq $_backslash_dq $_unicode ]
185
+ set - a b c
186
+ echo " $@ "
187
+ show_options
188
+ echo
144
189
145
- # Restore them
190
+ # dash that's not leading is not special
191
+ set x - y z
192
+ echo " $@ "
146
193
147
- . $varfile
148
- echo " Code saved to $varfile " 1>&2 # for debugging
194
+ # # STDOUT:
195
+ verbose-on
196
+ xtrace-on
149
197
150
- test " $_space " = ' [ ]' && echo OK
151
- test " $_whitespace " = $' [\t\r\n ]' && echo OK
152
- test " $_sq " = " 'single quotes'" && echo OK
153
- test " $_backslash_dq " = " \\ \" " && echo OK
154
- test " $_unicode " = $' [\u03bc]' && echo OK
198
+ a b c
155
199
156
- # # STDOUT:
157
- [ ]
158
- OK
159
- OK
160
- OK
161
- OK
162
- OK
200
+ x - y z
163
201
# # END
164
202
165
- # # BUG zsh status: 1
166
203
# # BUG zsh STDOUT:
167
- [ ]
204
+ verbose-on
205
+ xtrace-on
206
+
207
+ a b c
208
+ verbose-on
209
+ xtrace-on
210
+
211
+ x - y z
168
212
# # END
0 commit comments