【发布时间】:2021-08-26 15:16:51
【问题描述】:
我正在尝试运行命令 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!)
$
我显然在做一些明显的错误,我只是愚蠢地怀疑这是其中一件如此明显的事情,以至于我必须过于复杂自己的谷歌搜索来试图找到答案????
【问题讨论】:
-
| cat那是一只没用的猫。 -
呃……是吗?我的真实世界代码正在执行
> otherfile,所以我只是想我必须将它通过管道传递给 cat =D 嗯,我现在知道了 :)