Search code examples
linuxshellsshenvironment-variablesopenssh

How SSH Environment Variables works with shell script file?


If I run the command bellow and my install.sh has the following section:

export S3_URL=$PRD_URL
export S3_ACCESS_KEY=$PRD_S3_ACCESS_KEY
export S3_SECRET_KEY=$PRD_S3_SECRET_KEY

cat install.sh | ssh $PRD_USER@$PRD_HOST

The $PRD_S3_ACCESS_KEY is going to be resolved from my host or the environment variables from the remote server?


Solution

  • Assuming you have gettext installed (which contains envsubst), you can do

    envsubst < install.sh | ssh $PRD_USER@$PRD_HOST