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