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