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?

0

1 Answer 1

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.