How do I return a value other than $? from a ssh session
for example:
x=5
echo "$x"
ssh -o StrictHostKeyChecking=no root@hostname "x=10"
echo "$x"
This will print
5
5
But I need new value
5
10
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this:
What happens here is you capture the output of the command executed remotely, and assign that output to your local variable
x. Notice, that I used single quotes, not double quotes, to quote the remote command:'x=10; echo $x'.$xin a string in double quotes would get replaced by value of localxbefore being sent to the remote host, so you would get 5 printed by the remote command and assigned to your localx.