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