Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.