1 #!/bin/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 'tests' dir.
29 PATH=tests 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 ### Dependent export setting
73 # FOO is not respected here either.
74 export FOO=foo v=$(printenv.py FOO)
75 echo "v=$v"
76 # stdout: v=None