1 |
# |
2 |
# Tests for quotes. |
3 |
|
4 |
#### Unquoted words |
5 |
echo unquoted words |
6 |
## stdout: unquoted words |
7 |
|
8 |
#### Single-quoted |
9 |
echo 'single quoted' |
10 |
## stdout: single quoted |
11 |
|
12 |
#### Two single-quoted parts |
13 |
echo 'two single-quoted pa''rts in one token' |
14 |
## stdout: two single-quoted parts in one token |
15 |
|
16 |
#### Unquoted and single quoted |
17 |
echo unquoted' and single-quoted' |
18 |
## stdout: unquoted and single-quoted |
19 |
|
20 |
#### newline inside single-quoted string |
21 |
echo 'newline |
22 |
inside single-quoted string' |
23 |
## stdout-json: "newline\ninside single-quoted string\n" |
24 |
|
25 |
#### Double-quoted |
26 |
echo "double quoted" |
27 |
## stdout: double quoted |
28 |
|
29 |
#### Mix of quotes in one word |
30 |
echo unquoted' single-quoted'" double-quoted "unquoted |
31 |
## stdout: unquoted single-quoted double-quoted unquoted |
32 |
|
33 |
#### Var substitution |
34 |
FOO=bar |
35 |
echo "==$FOO==" |
36 |
## stdout: ==bar== |
37 |
|
38 |
#### Var substitution with braces |
39 |
FOO=bar |
40 |
echo foo${FOO} |
41 |
## stdout: foobar |
42 |
|
43 |
#### Var substitution with braces, quoted |
44 |
FOO=bar |
45 |
echo "foo${FOO}" |
46 |
## stdout: foobar |
47 |
|
48 |
#### Var length |
49 |
FOO=bar |
50 |
echo "foo${#FOO}" |
51 |
## stdout: foo3 |
52 |
|
53 |
#### Storing backslashes and then echoing them |
54 |
# This is a bug fix; it used to cause problems with unescaping. |
55 |
one='\' |
56 |
two='\\' |
57 |
echo $one $two |
58 |
echo "$one" "$two" |
59 |
## STDOUT: |
60 |
\ \\ |
61 |
\ \\ |
62 |
## END |
63 |
## BUG dash/mksh STDOUT: |
64 |
\ \ |
65 |
\ \ |
66 |
## END |
67 |
|
68 |
#### Backslash escapes |
69 |
echo \$ \| \a \b \c \d \\ |
70 |
## stdout: $ | a b c d \ |
71 |
|
72 |
#### Backslash escapes inside double quoted string |
73 |
echo "\$ \\ \\ \p \q" |
74 |
## stdout: $ \ \ \p \q |
75 |
|
76 |
#### C-style backslash escapes inside double quoted string |
77 |
# mksh and dash implement POSIX incompatible extensions. $ ` " \ <newline> |
78 |
# are the only special ones |
79 |
echo "\a \b" |
80 |
## stdout: \a \b |
81 |
## BUG dash/mksh stdout-json: "\u0007 \u0008\n" |
82 |
|
83 |
# BUG |
84 |
|
85 |
#### Literal $ |
86 |
echo $ |
87 |
## stdout: $ |
88 |
|
89 |
#### Quoted Literal $ |
90 |
echo $ "$" $ |
91 |
## stdout: $ $ $ |
92 |
|
93 |
#### Line continuation |
94 |
echo foo\ |
95 |
$ |
96 |
## stdout: foo$ |
97 |
|
98 |
#### Line continuation inside double quotes |
99 |
echo "foo\ |
100 |
$" |
101 |
## stdout: foo$ |
102 |
|
103 |
#### $? split over multiple lines |
104 |
# Same with $$, etc. OSH won't do this because $? is a single token. |
105 |
echo $\ |
106 |
? |
107 |
## stdout: $? |
108 |
## OK dash/bash/mksh/ash stdout: 0 |
109 |
|
110 |
# |
111 |
# Bad quotes |
112 |
# |
113 |
|
114 |
# TODO: Also test unterminated quotes inside ${} and $() |
115 |
|
116 |
#### Unterminated single quote |
117 |
## code: ls foo bar ' |
118 |
## status: 2 |
119 |
## OK mksh status: 1 |
120 |
|
121 |
#### Unterminated double quote |
122 |
## code: ls foo bar " |
123 |
## status: 2 |
124 |
## OK mksh status: 1 |
125 |
|
126 |
|
127 |
# |
128 |
# TODO: Might be another section? |
129 |
# |
130 |
|
131 |
#### Semicolon |
132 |
echo separated; echo by semi-colon |
133 |
## stdout-json: "separated\nby semi-colon\n" |
134 |
|
135 |
# |
136 |
# TODO: Variable substitution operators. |
137 |
# |
138 |
|
139 |
#### No tab escapes within single quotes |
140 |
# dash and mksh allow this, which is a BUG. |
141 |
# POSIX says: "Enclosing characters in single-quotes ( '' ) shall preserve the |
142 |
# literal value of each character within the single-quotes. A single-quote |
143 |
# cannot occur within single-quotes" |
144 |
echo 'a\tb' |
145 |
## stdout: a\tb |
146 |
## BUG dash/mksh stdout-json: "a\tb\n" |
147 |
|
148 |
# See if it supports ANSI C escapes. Bash supports this, but dash does NOT. I |
149 |
# guess dash you would do IFS=$(printf '\n\t') |
150 |
|
151 |
#### $'' |
152 |
echo $'foo' |
153 |
## stdout: foo |
154 |
## N-I dash stdout: $foo |
155 |
|
156 |
#### $'' with quotes |
157 |
echo $'single \' double \"' |
158 |
## stdout: single ' double " |
159 |
## N-I dash stdout-json: "" |
160 |
## N-I dash status: 2 |
161 |
|
162 |
#### $'' with newlines |
163 |
echo $'col1\ncol2\ncol3' |
164 |
## stdout-json: "col1\ncol2\ncol3\n" |
165 |
# In dash, \n is special within single quotes |
166 |
## N-I dash stdout-json: "$col1\ncol2\ncol3\n" |
167 |
|
168 |
#### $'' octal escapes don't have leading 0 |
169 |
# echo -e syntax is echo -e \0377 |
170 |
echo -n $'\001' $'\377' | od -A n -c | sed 's/ \+/ /g' |
171 |
## STDOUT: |
172 |
001 377 |
173 |
## END |
174 |
## N-I dash STDOUT: |
175 |
$ 001 $ 377 |
176 |
## END |
177 |
|
178 |
#### $'' octal escapes with fewer than 3 chars |
179 |
echo $'\1 \11 \11 \111' | od -A n -c | sed 's/ \+/ /g' |
180 |
## STDOUT: |
181 |
001 \t \t I \n |
182 |
## END |
183 |
## N-I dash STDOUT: |
184 |
$ 001 \t \t I \n |
185 |
## END |
186 |
|
187 |
#### Oil extension of \u{1234} to match QSN |
188 |
|
189 |
#shopt -s oil:upgrade |
190 |
|
191 |
# This is technically an incompatibility |
192 |
|
193 |
echo $'mu = \u{03bc}-\U{03bc}' |
194 |
## stdout-repr: 'mu = \xce\xbc-\xce\xbc\n' |
195 |
## N-I bash/ash STDOUT: |
196 |
mu = \u{03bc}-\U{03bc} |
197 |
## END |
198 |
## N-I dash STDOUT: |
199 |
$mu = \u{03bc}-\U{03bc} |
200 |
## END |
201 |
## N-I mksh STDOUT: |
202 |
mu = |
203 |
## END |
204 |
|
205 |
#### OSH allows invalid backslashes |
206 |
case $SH in (dash|mksh) exit ;; esac |
207 |
|
208 |
w=$'\uZ' |
209 |
x=$'\u{03bc' |
210 |
y=$'\z' |
211 |
echo $w $x $y |
212 |
## STDOUT: |
213 |
\uZ \u{03bc \z |
214 |
## END |
215 |
## N-I dash/mksh stdout-json: "" |
216 |
|
217 |
#### Oil parse errors with parse_backslash |
218 |
case $SH in (*osh) ;; (*) exit ;; esac |
219 |
shopt -s oil:all |
220 |
|
221 |
const w = c'\uZ' |
222 |
|
223 |
const x = c'\u{03bc' |
224 |
|
225 |
# Also invalid |
226 |
const y = c'\z' |
227 |
|
228 |
## stdout-json: "" |
229 |
## status: 2 |
230 |
## N-I dash/bash/mksh/ash status: 0 |
231 |
|
232 |
#### Oil allows unquoted foo\ bar |
233 |
shopt -s oil:all |
234 |
touch foo\ bar |
235 |
ls foo\ bar |
236 |
## STDOUT: |
237 |
foo bar |
238 |
## END |
239 |
|
240 |
#### $"" |
241 |
echo $"foo" |
242 |
## stdout: foo |
243 |
## N-I dash/ash stdout: $foo |
244 |
|
245 |
#### printf |
246 |
# This accepts \t by itself, hm. |
247 |
printf "c1\tc2\nc3\tc4\n" |
248 |
## stdout-json: "c1\tc2\nc3\tc4\n" |