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