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