Skip to content
Advertisement

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?

Advertisement

Answer

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

envsubst < install.sh | ssh $PRD_USER@$PRD_HOST
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement