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"nnOriginal contents:nn" && cat test.conf && printf "nnContents after envsubst < test.confnn" && envsubst < test.conf | cat && printf "nn"
Here are my results:
$ SIGNOFF="Goodbye" && printf "nOkay, $SIGNOFF has been set to "$SIGNOFF"nnOriginal contents:nn" && cat test.conf && printf "nnContents after envsubst < test.confnn" && envsubst < test.conf | cat && printf "nn" 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 😅
Advertisement
Answer
The variable is not exported, so it’s not visible to any command. Export it.
SIGNOFF="Goodbye" export SIGNOFF envsubst < file