Send variable with EOF and use host variable

8,805

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
Share:
8,805

Related videos on Youtube

callmemath
Author by

callmemath

Updated on September 18, 2022

Comments

  • callmemath
    callmemath over 1 year

    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
    

    ?