1 |
## compare_shells: bash mksh zsh ash
|
2 |
|
3 |
# dash doesn't have echo -e, $'', etc.
|
4 |
|
5 |
# TODO: fix J8 bug causing failure
|
6 |
|
7 |
# Cross-cutting test of serialization formats. That is, what J8 Notation
|
8 |
# should fix.
|
9 |
#
|
10 |
# TODO: Also see spec/xtrace for another use case.
|
11 |
|
12 |
|
13 |
case $SH in (ash) return ;; esac # yash and ash don't implement this
|
14 |
|
15 |
newline=$'one\ntwo'
|
16 |
printf '%q\n' "$newline"
|
17 |
|
18 |
quoted="$(printf '%q\n' "$newline")"
|
19 |
restored=$(eval "echo $quoted")
|
20 |
test "$newline" = "$restored" && echo roundtrip-ok
|
21 |
|
22 |
## STDOUT:
|
23 |
$'one\ntwo'
|
24 |
roundtrip-ok
|
25 |
## END
|
26 |
## OK mksh STDOUT:
|
27 |
'one'$'\n''two'
|
28 |
roundtrip-ok
|
29 |
## END
|
30 |
## OK zsh STDOUT:
|
31 |
one$'\n'two
|
32 |
roundtrip-ok
|
33 |
## END
|
34 |
## N-I ash stdout-json: ""
|
35 |
|
36 |
|
37 |
case $SH in (ash) return ;; esac # yash and ash don't implement this
|
38 |
|
39 |
# bash does a weird thing and uses \
|
40 |
|
41 |
spaces='one two'
|
42 |
printf '%q\n' "$spaces"
|
43 |
|
44 |
## STDOUT:
|
45 |
'one two'
|
46 |
## END
|
47 |
## OK bash/zsh STDOUT:
|
48 |
one\ two
|
49 |
## END
|
50 |
## N-I ash stdout-json: ""
|
51 |
|
52 |
|
53 |
case $SH in (ash) return ;; esac # yash and ash don't implement %q
|
54 |
|
55 |
quotes=\'\"
|
56 |
printf '%q\n' "$quotes"
|
57 |
|
58 |
quoted="$(printf '%q\n' "$quotes")"
|
59 |
restored=$(eval "echo $quoted")
|
60 |
test "$quotes" = "$restored" && echo roundtrip-ok
|
61 |
|
62 |
## STDOUT:
|
63 |
\'\"
|
64 |
roundtrip-ok
|
65 |
## END
|
66 |
## OK osh STDOUT:
|
67 |
$'\'"'
|
68 |
roundtrip-ok
|
69 |
## END
|
70 |
## BUG mksh STDOUT:
|
71 |
''\''"'
|
72 |
roundtrip-ok
|
73 |
## END
|
74 |
## N-I ash stdout-json: ""
|
75 |
|
76 |
|
77 |
case $SH in (ash) return ;; esac # yash and ash don't implement this
|
78 |
|
79 |
unprintable=$'\xff'
|
80 |
printf '%q\n' "$unprintable"
|
81 |
|
82 |
# bash and zsh agree
|
83 |
## STDOUT:
|
84 |
$'\377'
|
85 |
## END
|
86 |
## OK osh STDOUT:
|
87 |
$'\xff'
|
88 |
## END
|
89 |
## BUG mksh STDOUT:
|
90 |
''$'\377'
|
91 |
## END
|
92 |
## N-I ash stdout-json: ""
|
93 |
|
94 |
|
95 |
case $SH in (ash) return ;; esac # yash and ash don't implement this
|
96 |
|
97 |
unicode=$'\u03bc'
|
98 |
unicode=$'\xce\xbc' # does the same thing
|
99 |
|
100 |
printf '%q\n' "$unicode"
|
101 |
|
102 |
# Oil issue: we have quotes. Isn't that OK?
|
103 |
## STDOUT:
|
104 |
μ
|
105 |
## END
|
106 |
## OK osh STDOUT:
|
107 |
'μ'
|
108 |
## END
|
109 |
## N-I ash stdout-json: ""
|
110 |
|
111 |
|
112 |
case $SH in (ash) return ;; esac
|
113 |
|
114 |
# Hm bash/mksh/zsh understand these. They are doing decoding and error
|
115 |
# recovery! inspecting the bash source seems to confirm this.
|
116 |
unicode=$'\xce'
|
117 |
printf '%q\n' "$unicode"
|
118 |
|
119 |
unicode=$'\xce\xce\xbc'
|
120 |
printf '%q\n' "$unicode"
|
121 |
|
122 |
unicode=$'\xce\xbc\xce'
|
123 |
printf '%q\n' "$unicode"
|
124 |
|
125 |
case $SH in (mksh) return ;; esac # it prints unprintable chars here!
|
126 |
|
127 |
unicode=$'\xcea'
|
128 |
printf '%q\n' "$unicode"
|
129 |
unicode=$'a\xce'
|
130 |
printf '%q\n' "$unicode"
|
131 |
## STDOUT:
|
132 |
$'\xce'
|
133 |
$'\xceμ'
|
134 |
$'μ\xce'
|
135 |
$'\xcea'
|
136 |
$'a\xce'
|
137 |
## END
|
138 |
## OK bash STDOUT:
|
139 |
$'\316'
|
140 |
$'\316μ'
|
141 |
$'μ\316'
|
142 |
$'\316a'
|
143 |
$'a\316'
|
144 |
## END
|
145 |
## BUG mksh STDOUT:
|
146 |
''$'\316'
|
147 |
''$'\316''μ'
|
148 |
'μ'$'\316'
|
149 |
## END
|
150 |
## OK zsh STDOUT:
|
151 |
$'\316'
|
152 |
$'\316'μ
|
153 |
μ$'\316'
|
154 |
$'\316'a
|
155 |
a$'\316'
|
156 |
## END
|
157 |
## N-I ash stdout-json: ""
|
158 |
|
159 |
|
160 |
case $SH in (zsh) return ;; esac # zsh doesn't make much sense
|
161 |
|
162 |
zz=$'one\ntwo'
|
163 |
|
164 |
set | grep zz
|
165 |
## STDOUT:
|
166 |
zz=$'one\ntwo'
|
167 |
## END
|
168 |
## OK ash stdout-json: "zz='one\n"
|
169 |
## BUG zsh stdout-json: ""
|
170 |
|
171 |
|
172 |
|
173 |
case $SH in (ash|zsh) return ;; esac # zsh doesn't make much sense
|
174 |
|
175 |
zz=$'one\ntwo'
|
176 |
|
177 |
typeset | grep zz
|
178 |
typeset -p zz
|
179 |
|
180 |
## STDOUT:
|
181 |
zz=$'one\ntwo'
|
182 |
declare -- zz=$'one\ntwo'
|
183 |
## END
|
184 |
|
185 |
## OK mksh STDOUT:
|
186 |
typeset zz
|
187 |
typeset zz=$'one\ntwo'
|
188 |
## BUG zsh stdout-json: ""
|
189 |
## N-I ash stdout-json: ""
|
190 |
|
191 |
|
192 |
case $SH in (zsh|ash) exit ;; esac
|
193 |
|
194 |
zz=$'one\ntwo \u03bc'
|
195 |
|
196 |
# weirdly, quoted and unquoted aren't different
|
197 |
echo ${zz@Q}
|
198 |
echo "${zz@Q}"
|
199 |
## STDOUT:
|
200 |
$'one\ntwo μ'
|
201 |
$'one\ntwo μ'
|
202 |
## END
|
203 |
## OK mksh STDOUT:
|
204 |
$'one
|
205 |
two μ'
|
206 |
$'one
|
207 |
two μ'
|
208 |
## END
|
209 |
## N-I ash/zsh stdout-json: ""
|
210 |
|
211 |
|
212 |
zz=$'one\ntwo'
|
213 |
set -x
|
214 |
echo "$zz"
|
215 |
## STDOUT:
|
216 |
one
|
217 |
two
|
218 |
## END
|
219 |
## STDERR:
|
220 |
+ echo $'one\ntwo'
|
221 |
## END
|
222 |
## OK bash/ash STDERR:
|
223 |
+ echo 'one
|
224 |
two'
|
225 |
## END
|
226 |
## OK zsh STDERR:
|
227 |
+zsh:3> echo 'one
|
228 |
two'
|
229 |
## END
|
230 |
|