2

I want to send variable from source to host, and exec host script. Here is my code :

var1=1
ssh -p 42 root@xxx /bin/bash << EOF
  var2=2
  echo $var1
  echo $var2
EOF

Return : 1

var1=1
ssh -p 42 root@xxx /bin/bash << \EOF
  var2=2
  echo $var1
  echo $var2
EOF

Return : 2

How to return :

1
2

?

1 Answers1

5

You want your local shell to expand $var1 but the remote shell to expand $var2:

var1=1
ssh -p 42 root@xxx /bin/bash << EOF    # un-quoted/escaped
  var2=2
  echo $var1
  echo \$var2
EOF
glenn jackman
  • 85,964