我正在尝试运行命令envsubst < myfile来替换环境变量,但是它们并没有被替换为它们的值,而是被替换为空字符串。
下面是我的示例命令(为清楚起见,拆分成单独的行):
SIGNOFF="Goodbye"
&&
printf "\nOkay, \$SIGNOFF has been set to \"$SIGNOFF\"\n\nOriginal contents:\n\n"
&&
cat test.conf
&&
printf "\n\nContents after envsubst < test.conf\n\n"
&&
envsubst < test.conf | cat
&&
printf "\n\n"以下是我的结果:
$ SIGNOFF="Goodbye" && printf "\nOkay, \$SIGNOFF has been set to \"$SIGNOFF\"\n\nOriginal contents:\n\n" && cat test.conf && printf "\n\nContents after envsubst < test.conf\n\n" && envsubst < test.conf | cat && printf "\n\n"
Okay, $SIGNOFF has been set to "Goodbye"
Original contents:
Hello world, let's change the variable in the quotes below to say Goodbye!
"$SIGNOFF" (it certainly shouldn't just be blank!)
Contents after envsubst < test.conf
Hello world, let's change the variable in the quotes below to say Goodbye!
"" (it certainly shouldn't just be blank!)
$ 我显然在做一些明显错误的事情,我只是有一个愚蠢的怀疑这是很明显的事情之一,我必须在我自己的谷歌搜索中过于复杂地试图找到答案?
发布于 2021-06-09 23:26:09
该变量不会导出,因此对任何命令都不可见。将其导出。
SIGNOFF="Goodbye"
export SIGNOFF
envsubst < filehttps://stackoverflow.com/questions/67907177
复制相似问题