I've exposed one system environment variable say KEY1 with value VALUE1 in /etc/profile (I know, I know, it's probably bad)
Now in my shell if I do
$ echo $KEY1
VALUE1
But when I do
$ python -c "import os; print os.environ.get('KEY1')"
None
$
Why might this be the case?
You might not have exported the variable. You can think of export as a way of making a shell variable public and not private to the shell. Take a look at the export man page.
➜ ~ K=1
➜ ~ echo $K
1
➜ ~ python -c "import os; print os.environ.get('K')"
None
➜ ~ export K=1
➜ ~ python -c "import os; print os.environ.get('K')"
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With