Search code examples
linuxenvironment-variablesenvsubst

envsubst works only for part of the variables


I have a file with some $VARIABLES which I want to substitute using envsubst tool. But in my case the tool is substituting only +/- half of the variables.

To illustrate: I have a file .env with some variables:

MODE=HTTP
URL=https://some.url:0000/xyz

I use

$ source .env

And now, when both of the variables are set only MODE is correctly used by envsubst

echo $MODE 
HTTP
echo 'mode: $MODE' | envsubst
mode: HTTP


echo $URL
https://some.url:0000/xyz
echo 'url: $URL' | envsubst
url:

Any ideas why envsubst not working for all variables?


Solution

  • I guess that it's only working for $MODE by accident - because you have an exported $MODE variable in your shell.

    In order for envsubst to work it needs to inherit the environment variables from your shell which is only done for exported variables.

    It'll work if your .env file exports the variables:

    MODE=HTTP
    URL=https://some.url:0000/xyz
    
    export MODE
    export URL