OILS / spec / var-sub.test.sh View on Github | oils.pub

64 lines, 16 significant
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
9echo ${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.
16echo ${foo:-$({ ls /bin/ls; })}
17## stdout: /bin/ls
18
19#### Nested ${}
20bar=ZZ
21echo ${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'
30fun() {
31 echo hi > "$@"
32}
33fun _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
42set -- '2 3' 'c d'
43echo 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.
56fun() {
57 cat << "$@"
58hi
591 2
60}
61fun 1 2
62## status: 2
63## stdout-json: ""
64## OK mksh status: 1