我試圖運行我去測試這個樣子,設置環境變量:設置環境變量測試
FOO=BAR go list ./... | grep -v vendor | xargs -n1 go test -timeout=3s
在我的測試中,我做的事:
log.Print(os.Getenv("FOO"))
它返回一個空字符串。爲什麼FOO沒有設置?
我試圖運行我去測試這個樣子,設置環境變量:設置環境變量測試
FOO=BAR go list ./... | grep -v vendor | xargs -n1 go test -timeout=3s
在我的測試中,我做的事:
log.Print(os.Getenv("FOO"))
它返回一個空字符串。爲什麼FOO沒有設置?
FOO=BAR bash -c 'go list ./... | grep -v vendor | xargs -n1 go test -timeout=3s'
很好地解釋了爲什麼原來的命令不起作用可以在問題的答案中找到:https://unix.stackexchange.com/questions/134735/environment-variables-are-not-set-when-my-function-is-called-in-a-pipeline
管道這還不怎麼設置變量的工作。請參閱:
FOO=BAR echo "AAA" | FOO=WAZ printenv | grep FOO
噢,謝謝。這工作。我現在感到很蠢。 –
請注意解釋這一點? ;) –
http://unix.stackexchange.com/questions/134735/environment-variables-are-not-set-when-my-function-is-called-in-a-pipeline – kostya