2012-10-24 58 views
1

分配如預期的那樣多字符串FOO作品:提供一個環境變量到Python子進程和另一個不

$ read -d '' FOO <<"EOF" 
> the content 
> EOF 
$ echo $FOO 
the content 
$ python -c "import os; print os.environ.get('FOO')" 
the content 

看似與FOO_BAR_BAZ原理不同同樣的事情:

$ read -d '' FOO_BAR_BAZ <<"EOF" 
> the content 
> EOF 
$ echo $FOO_BAR_BAZ 
the content 
$ python -c "import os; print os.environ.get('FOO_BAR_BAZ')" 
None 

我要麼一個微妙的錯誤或誤解。

回答

2

您是否export FOO但不是export FOO_BAR_BAZ?環境變量只有在子進程(如Python)已經被導出時纔可見。

+0

太好了,謝謝!將接受一些。所以,我可以使用'read -d''FOO_BAR_BAZ'來完成賦值,然後在那之後'輸出FOO_BAR_BAZ'。 –

相關問題