-1

I use SSH with a heredoc to control remote PC:

val=0    
ssh -p 1046 name@10.122.78.99 > result.txt 2>&1 << 'eeooff'
    echo $PATH
    echo "start"
    export vv=333
    echo $vv
    echo "end"
    val=10
eeooff
echo $val

When I check result.txt, I found echo $PATH works, but echo $vv gives nothing. Why? Is setting a variable forbidden when using SSH with a heredoc?

And $val is still 0. How to modify to 10 when using SSH with a heredoc?

Biffen
  • 6,249
  • 6
  • 28
  • 36
Jim Green
  • 1,088
  • 3
  • 15
  • 40
  • 1
    I think you should ask other question and leave this question as it was. Changing the question to ask something completly different when you have a answer is not very fair, because people who have the same question as your old one was will not reach the answers to your question, edit is fair when you want to clarify your question, but no for asking something completly different. Because this I have choosed to remove my upvote. – sergiotarxz Jan 23 '19 at 09:41
  • you are right. I recover the question , and bold the left question what I want to know next. – Jim Green Jan 23 '19 at 10:46

2 Answers2

1

Your local shell is the one who have expand $vv, you must escape it like this \$vv.

Excuse my english.

sergiotarxz
  • 520
  • 2
  • 14
0

You can also:

ssh -p 1046 name@10.122.78.99 > result.txt 2>&1 << 'eeooff'

This will avoid all variable expansion. Seen here: How to avoid heredoc expanding variables?

sergiotarxz
  • 520
  • 2
  • 14