1 #
2 # Corner cases in var sub. Maybe rename this file.
3
4 #### Bad var sub
5 echo ${a&}
6 ## stdout-json: ""
7 ## status: 2
8 ## OK bash/mksh status: 1
9
10 #### Braced block inside ${}
11 # NOTE: This bug was in bash 4.3 but fixed in bash 4.4.
12 echo ${foo:-$({ which ls; })}
13 ## stdout: /bin/ls
14
15 #### Nested ${}
16 bar=ZZ
17 echo ${foo:-${bar}}
18 ## stdout: ZZ
19
20 #### Filename redirect with "$@"
21 # bash - ambiguous redirect -- yeah I want this error
22 # - But I want it at PARSE time? So is there a special DollarAtPart?
23 # MultipleArgsPart?
24 # mksh - tries to create '_tmp/var-sub1 _tmp/var-sub2'
25 # dash - tries to create '_tmp/var-sub1 _tmp/var-sub2'
26 fun() {
27 echo hi > "$@"
28 }
29 fun _tmp/var-sub1 _tmp/var-sub2
30 ## status: 1
31 ## OK dash status: 2
32
33 #### Filename redirect with split word
34 # bash - runtime error, ambiguous redirect
35 # mksh and dash - they will NOT apply word splitting after redirect, and write
36 # to '_tmp/1 2'
37 # Stricter behavior seems fine.
38 foo='_tmp/1 2'
39 rm '_tmp/1 2'
40 echo hi > $foo
41 test -f '_tmp/1 2' && cat '_tmp/1 2'
42 ## status: 0
43 ## stdout: hi
44 ## OK bash status: 1
45 ## OK bash stdout-json: ""
46
47 #### Descriptor redirect to bad "$@"
48 # All of them give errors:
49 # dash - bad fd number, parse error?
50 # bash - ambiguous redirect
51 # mksh - illegal file descriptor name
52 set -- '2 3' 'c d'
53 echo hi 1>& "$@"
54 ## status: 1
55 ## OK dash status: 2
56
57 #### Here doc with bad "$@" delimiter
58 # bash - syntax error
59 # dash - syntax error: end of file unexpected
60 # mksh - runtime error: here document unclosed
61 #
62 # What I want is syntax error: bad delimiter!
63 #
64 # This means that "$@" should be part of the parse tree then? Anything that
65 # involves more than one token.
66 fun() {
67 cat << "$@"
68 hi
69 1 2
70 }
71 fun 1 2
72 ## status: 2
73 ## stdout-json: ""
74 ## OK mksh status: 1