You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在命令中使用键值对文件的环境变量?值可包含空格

问题情况

我看到一篇很棒的问答,但无法将其适配到我的命令中:

$ echo 'TEST="value with spaces"' > .env

$ cat .env
TEST="value with spaces"

$ env $(cat .env | xargs -d "
" ) echo $TEST
env: with: No such file or directory

$ export $(cat .env | xargs -d "
" ) echo $TEST
-bash: export: `spaces"': not a valid identifier

我可以使用eval,但它会污染我的环境:

$ eval $(cat .env | xargs -d "
" ); echo $TEST
value with spaces

$ echo $TEST
value with spaces

内容的提问来源于stack exchange,提问作者Eugen Konkov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 18:52:04