1 |
#!/usr/bin/env bash |
2 |
|
3 |
### Env value doesn't persist |
4 |
FOO=foo printenv.py FOO |
5 |
echo [$FOO] |
6 |
# stdout-json: "foo\n[]\n" |
7 |
|
8 |
### Env value with equals |
9 |
FOO=foo=foo printenv.py FOO |
10 |
# stdout: foo=foo |
11 |
|
12 |
### Env value using preceding Env binding |
13 |
# This means that for ASSIGNMENT_WORD, on the RHS you invoke the parser again! |
14 |
# Could be any kind of quoted string. |
15 |
FOO="foo" BAR="[$FOO]" printenv.py FOO BAR |
16 |
# stdout-json: "foo\n[foo]\n" |
17 |
# BUG mksh stdout-json: "foo\n[]\n" |
18 |
|
19 |
### Env value with two quotes |
20 |
FOO='foo'"adjacent" printenv.py FOO |
21 |
# stdout: fooadjacent |
22 |
|
23 |
### Env value with escaped < |
24 |
FOO=foo\<foo printenv.py FOO |
25 |
# stdout: foo<foo |
26 |
|
27 |
### Escaped = in command name |
28 |
# foo=bar is in the 'spec/bin' dir. |
29 |
foo\=bar |
30 |
# stdout: HI |
31 |
|
32 |
### Env binding not allowed before compound command |
33 |
# bash gives exit code 2 for syntax error, because of 'do'. |
34 |
# dash gives 0 because there is stuff after for? Should really give an error. |
35 |
# mksh gives acceptable error of 1. |
36 |
FOO=bar for i in a b; do printenv.py $FOO; done |
37 |
# BUG dash status: 0 |
38 |
# OK mksh status: 1 |
39 |
# status: 2 |
40 |
|
41 |
### Trying to run keyword 'for' |
42 |
FOO=bar for |
43 |
# status: 127 |
44 |
|
45 |
### Empty env binding |
46 |
EMPTY= printenv.py EMPTY |
47 |
# stdout: |
48 |
|
49 |
### Assignment doesn't do word splitting |
50 |
words='one two' |
51 |
a=$words |
52 |
argv.py "$a" |
53 |
# stdout: ['one two'] |
54 |
|
55 |
### Assignment doesn't do glob expansion |
56 |
touch _tmp/z.Z _tmp/zz.Z |
57 |
a=_tmp/*.Z |
58 |
argv.py "$a" |
59 |
# stdout: ['_tmp/*.Z'] |
60 |
|
61 |
### Env binding in readonly/declare disallowed |
62 |
# I'm disallowing this in the oil shell, because it doesn't work in bash! |
63 |
# (v=None vs v=foo) |
64 |
# assert status 2 for parse error, but allow stdout v=None/status 0 for |
65 |
# existing implementations. |
66 |
FOO=foo readonly v=$(printenv.py FOO) |
67 |
echo "v=$v" |
68 |
# OK bash/dash/mksh stdout: v=None |
69 |
# OK bash/dash/mksh status: 0 |
70 |
# status: 2 |
71 |
|
72 |
### local -a |
73 |
# nixpkgs setup.sh uses this (issue #26) |
74 |
f() { |
75 |
local -a array=(x y z) |
76 |
argv.py "${array[@]}" |
77 |
} |
78 |
f |
79 |
# stdout: ['x', 'y', 'z'] |
80 |
# N-I dash stdout-json: "" |
81 |
# N-I dash status: 2 |
82 |
# N-I mksh stdout-json: "" |
83 |
# N-I mksh status: 1 |
84 |
|
85 |
### declare -a |
86 |
# nixpkgs setup.sh uses this (issue #26) |
87 |
declare -a array=(x y z) |
88 |
argv.py "${array[@]}" |
89 |
# stdout: ['x', 'y', 'z'] |
90 |
# N-I dash stdout-json: "" |
91 |
# N-I dash status: 2 |
92 |
# N-I mksh stdout-json: "" |
93 |
# N-I mksh status: 1 |
94 |
|
95 |
### typeset -a a[1]=a a[3]=c |
96 |
# declare works the same way in bash, but not mksh. |
97 |
# spaces are NOT allowed here. |
98 |
typeset -a a[1*1]=x a[1+2]=z |
99 |
argv.py "${a[@]}" |
100 |
# stdout: ['x', 'z'] |
101 |
# N-I dash stdout-json: "" |
102 |
# N-I dash status: 2 |
103 |
|
104 |
### indexed LHS without spaces is allowed |
105 |
a[1 * 1]=x a[ 1 + 2 ]=z |
106 |
argv.py "${a[@]}" |
107 |
# stdout: ['x', 'z'] |
108 |
# N-I dash stdout-json: "" |
109 |
# N-I dash status: 2 |