I'm trying to run the command envsubst < myfile
to replace environment variables but instead of being replaced with their values, they are being replaced with blank strings.
Here's my example command (split onto separate lines for clarity):
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"
Here are my results:
$ 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!)
$
I'm clearly doing something obvious wrong, I just have a silly suspicion it's one of those things that is so obvious that I must be overly complicating my own google searches in trying to find an answer 😅
The variable is not exported, so it's not visible to any command. Export it.
SIGNOFF="Goodbye"
export SIGNOFF
envsubst < file