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