3

When executing this bash script, it only shows my local path.

ssh ${REMOTE_HOST} 'bash -s' <<EOL
    set -e
    source ~/.profile
    echo $PATH
    # Commands here don't work because $PATH is not set properly.
    # How can I see what $PATH is set to here?
EOL

How can I view the remote value of $PATH to debug this?

Flash
  • 133

1 Answers1

4

The $PATH is getting expanded prior to running on the remote server.

Example #1

Say I run these commands from a system called skinner.bubba.net.

[root@skinner ~]# ssh mulder 'bash -s' <<EOL
>   echo $HOSTNAME
>   hostname
> EOL
skinner.bubba.net
mulder.bubba.net

By moving the single quote so that the echo $HOSTNAME is inside it, you can guard the variable from getting expanded by skinner's Bash shell.

[root@skinner ~]# ssh mulder 'bash -s <<EOL
>   echo $HOSTNAME
>   hostname
> EOL'
mulder.bubba.net
mulder.bubba.net

Example #2

The other method would be to escape the $HOSTNAME with a slash, which tells Bash you want to send a literal dollar sign.

[root@skinner ~]# ssh mulder 'bash -s' <<EOL
>   echo \$HOSTNAME
>   hostname
> EOL
mulder.bubba.net
mulder.bubba.net
slm
  • 369,824