1 ## our_shell: ysh
2 ## oils_failures_allowed: 2
3
4 #### single quoted -- implicit and explicit raw
5 var x = 'foo bar'
6 echo $x
7 setvar x = r'foo bar' # Same string
8 echo $x
9 setvar x = r'\t\n' # This is raw
10 echo $x
11 ## STDOUT:
12 foo bar
13 foo bar
14 \t\n
15 ## END
16
17 #### Implicit raw single quote with backslash is a syntax error
18 var x = '\t\n'
19 echo $x
20 ## status: 2
21 ## stdout-json: ""
22
23 #### single quoted C strings: $'foo\n'
24
25 # expression mode
26 var x = $'foo\nbar'
27 echo "$x"
28
29 # command mode
30 if test "$x" = $'foo\nbar'; then
31 echo equal
32 fi
33
34 ## STDOUT:
35 foo
36 bar
37 equal
38 ## END
39
40 #### Double Quoted
41 var name = 'World'
42 var g = "Hello $name"
43
44 echo "Hello $name"
45 echo $g
46 ## STDOUT:
47 Hello World
48 Hello World
49 ## END
50
51 #### Multiline strings with '' and ""
52
53 var single = '
54 single
55 '
56
57 var x = 42
58 var double = "
59 double $x
60 "
61
62 echo $single
63 echo $double
64
65 ## STDOUT:
66
67 single
68
69
70 double 42
71
72 ## END
73
74 #### C strings in %() array literals
75 shopt -s oil:upgrade
76
77 var lines=%($'aa\tbb' $'cc\tdd')
78 write @lines
79
80 ## STDOUT:
81 aa bb
82 cc dd
83 ## END
84
85 #### shopt parse_raw_string
86
87 # Ignored prefix
88 echo r'\'
89
90 # space
91 write r '' end
92
93 # These use shell rules!
94 echo ra'\'
95 echo raw'\'
96
97 echo r"\\"
98
99 # Now it's a regular r
100 shopt --unset parse_raw_string
101 write unset r'\'
102
103 ## STDOUT:
104 \
105 r
106
107 end
108 ra\
109 raw\
110 r\
111 unset
112 r\
113 ## END
114
115 #### Triple Double Quotes, Expression Mode
116
117 var line1 = """line1"""
118 echo line1=$line1
119 var line2 = """
120 line2"""
121 echo line2=$line2
122
123 var two = 2
124 var three = 3
125 var x = """
126 one "
127 two = $two ""
128 three = $three
129 """
130 echo "[$x]"
131
132 var x = """
133 good
134 bad
135 """
136 echo "[$x]"
137
138 ## STDOUT:
139 line1=line1
140 line2=line2
141 [one "
142 two = 2 ""
143 three = 3
144 ]
145 [good
146 bad
147 ]
148 ## END
149
150 #### Triple Single Quotes, Expression Mode (TODO: j""")
151
152 var two = 2
153 var three = 2
154
155 var x = '''
156 two = $two '
157 three = $three ''
158 \u{61}
159 '''
160 echo "[$x]"
161
162 var x = $'''
163 two = $two '
164 three = $three ''
165 \u{61}
166 '''
167 echo "[$x]"
168
169 ## STDOUT:
170 [two = $two '
171 three = $three ''
172 \u{61}
173 ]
174 [two = $two '
175 three = $three ''
176 a
177 ]
178 ## END
179
180
181 #### Triple Double Quotes, Command Mode
182
183 var two=2
184 var three=3
185
186 echo ""a # test lookahead
187
188 echo --
189 echo """
190 one "
191 two = $two ""
192 three = $three
193 """
194
195 echo --
196 tac <<< """
197 one "
198 two = $two ""
199 three = $three
200 """
201
202 shopt --unset parse_triple_quote
203
204 echo --
205 echo """
206 one
207 two = $two
208 three = $three
209 """
210
211
212 ## STDOUT:
213 a
214 --
215 one "
216 two = 2 ""
217 three = 3
218
219 --
220
221 three = 3
222 two = 2 ""
223 one "
224 --
225
226 one
227 two = 2
228 three = 3
229
230 ## END
231
232 #### raw strings and triple quotes
233
234 echo r'''a'''
235
236 shopt --unset parse_raw_string
237
238 echo r'''a'''
239
240 ## STDOUT:
241 a
242 ra
243 ## END
244
245
246 #### Triple Single Quotes, Command Mode
247
248 echo ''a # make sure lookahead doesn't mess up
249
250 echo --
251 echo '''
252 two = $two
253 '
254 '' '
255 \u{61}
256 '''
257 ## STDOUT:
258 a
259 --
260 two = $two
261 '
262 '' '
263 \u{61}
264
265 ## END
266
267 #### Triple Single Quotes, Here Doc
268
269 tac <<< '''
270 two = $two
271 '
272 '' '
273 \u{61}
274 '''
275
276 ## STDOUT:
277
278 \u{61}
279 '' '
280 '
281 two = $two
282 ## END
283
284 #### Triple Single Quotes, disabled
285
286 shopt --unset parse_triple_quote
287
288 echo '''
289 two = $two
290 \u{61}
291 '''
292
293 ## STDOUT:
294
295 two = $two
296 \u{61}
297
298 ## END
299
300
301 #### $''' in command mode (TODO: j""")
302
303 echo $'''
304 two = $two
305 '
306 '' '
307 \u{61}
308 '''
309
310 ## STDOUT:
311 two = $two
312 '
313 '' '
314 a
315
316 ## END
317
318 #### here doc with quotes
319
320 # This has 3 right double quotes
321
322 cat <<EOF
323 "hello"
324 ""
325 """
326 EOF
327
328
329 ## STDOUT:
330 "hello"
331 ""
332 """
333 ## END
334
335 #### triple quoted and implicit concatenation
336
337 # Should we allow this? Or I think it's possible to make it a syntax error
338
339 echo '''
340 single
341 '''zz
342
343 echo """
344 double
345 """zz
346 ## status: 2
347 ## stdout-json: ""