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