| 1 | #!/bin/bash |
| 2 | |
| 3 | ### Env value with equals |
| 4 | FOO=foo=foo printenv.py FOO |
| 5 | # stdout: foo=foo |
| 6 | |
| 7 | ### Env value using preceding Env binding |
| 8 | # This means that for ASSIGNMENT_WORD, on the RHS you invoke the parser again! |
| 9 | # Could be any kind of quoted string. |
| 10 | FOO="foo" BAR="[$FOO]" printenv.py FOO BAR |
| 11 | # stdout-json: "foo\n[foo]\n" |
| 12 | # BUG mksh stdout-json: "foo\n[]\n" |
| 13 | |
| 14 | ### Env value with two quotes |
| 15 | FOO='foo'"adjacent" printenv.py FOO |
| 16 | # stdout: fooadjacent |
| 17 | |
| 18 | ### Env value with escaped < |
| 19 | FOO=foo\<foo printenv.py FOO |
| 20 | # stdout: foo<foo |
| 21 | |
| 22 | ### Escaped = in command name |
| 23 | # foo=bar is in the 'tests' dir. |
| 24 | PATH=tests foo\=bar |
| 25 | # stdout: HI |
| 26 | |
| 27 | ### Env binding not allowed before compound command |
| 28 | # bash gives exit code 2 for syntax error, because of 'do'. |
| 29 | # dash gives 0 because there is stuff after for? Should really give an error. |
| 30 | # mksh gives acceptable error of 1. |
| 31 | FOO=bar for i in a b; do printenv.py $FOO; done |
| 32 | # BUG dash status: 0 |
| 33 | # OK mksh status: 1 |
| 34 | # status: 2 |
| 35 | |
| 36 | ### Trying to run keyword 'for' |
| 37 | FOO=bar for |
| 38 | # status: 127 |
| 39 | |
| 40 | ### Empty env binding |
| 41 | EMPTY= printenv.py EMPTY |
| 42 | # stdout: |
| 43 | |
| 44 | ### Assignment doesn't do word splitting |
| 45 | words='one two' |
| 46 | a=$words |
| 47 | argv.py "$a" |
| 48 | # stdout: ['one two'] |
| 49 | |
| 50 | ### Assignment doesn't do glob expansion |
| 51 | touch _tmp/z.Z _tmp/zz.Z |
| 52 | a=_tmp/*.Z |
| 53 | argv.py "$a" |
| 54 | # stdout: ['_tmp/*.Z'] |
| 55 | |
| 56 | ### Env binding in readonly/declare disallowed |
| 57 | # I'm disallowing this in the oil shell, because it doesn't work in bash! |
| 58 | # (v=None vs v=foo) |
| 59 | # assert status 2 for parse error, but allow stdout v=None/status 0 for |
| 60 | # existing implementations. |
| 61 | FOO=foo readonly v=$(printenv.py FOO) |
| 62 | echo "v=$v" |
| 63 | # OK bash/dash/mksh stdout: v=None |
| 64 | # OK bash/dash/mksh status: 0 |
| 65 | # status: 2 |
| 66 | |
| 67 | ### Dependent export setting |
| 68 | # FOO is not respected here either. |
| 69 | export FOO=foo v=$(printenv.py FOO) |
| 70 | echo "v=$v" |
| 71 | # stdout: v=None |