(This is RHEL 8.4, if it matters.)
The echo
commands on lines 5 and 7 in this script run on the local host, but the hostname
commands on lines 6 and 8 run on the remote host as expected.
Why do lines 5 and 7 run on the local host? More importantly, how do I get them to run on the remote host?
EDIT: I do not want to pass in variables. I want the variables to be solely defined and used on the remote server.
1 #!/bin/bash
2 export foo=bar
3 ssh -q ${1} <<EOF
4 export foo=blarge
5 echo $foo
6 hostname
7 echo $foo
8 hostname
9 EOF
10 hostname