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-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
188 #### OSH allows invalid backslashes
189 case $SH in (dash|mksh) exit ;; esac
190
191 w=$'\uZ'
192 x=$'\u{03bc'
193 y=$'\z'
194 echo $w $x $y
195 ## STDOUT:
196 \uZ \u{03bc \z
197 ## END
198 ## N-I dash/mksh stdout-json: ""
199
200 #### YSH parse errors with parse_backslash
201 case $SH in (*osh) ;; (*) exit ;; esac
202 shopt -s oil:all
203
204 const w = c'\uZ'
205
206 const x = c'\u{03bc'
207
208 # Also invalid
209 const y = c'\z'
210
211 ## stdout-json: ""
212 ## status: 2
213 ## N-I dash/bash/mksh/ash status: 0
214
215 #### Oil allows unquoted foo\ bar
216 shopt -s oil:all
217 touch foo\ bar
218 ls foo\ bar
219 ## STDOUT:
220 foo bar
221 ## END
222
223 #### $""
224 echo $"foo"
225 ## stdout: foo
226 ## N-I dash/ash stdout: $foo
227
228 #### printf
229 # This accepts \t by itself, hm.
230 printf "c1\tc2\nc3\tc4\n"
231 ## stdout-json: "c1\tc2\nc3\tc4\n"