我正在嘗試像這樣運行我的 Go 測試,設置一個環境變量:FOO=BAR go list ./... | grep -v vendor | xargs -n1 go test -timeout=3s在我的測試中,我這樣做:log.Print(os.Getenv("FOO"))它返回一個空字符串。為什么沒有設置FOO?
3 回答

慕雪6442864
TA貢獻1812條經驗 獲得超5個贊
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 -被稱為管道中
- 3 回答
- 0 關注
- 396 瀏覽
添加回答
舉報
0/150
提交
取消