我试图运行我去测试这个样子,设置环境变量:设置环境变量测试
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