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