The ` and $ characters are probably being interpreted by the local shell, try escaping them with \
How can I pass the output of the command to variable while in SSH remote session?
Pregunta
I am trying to store the output of a command executed via SSH remote session into a variable, but it seems I got some errors. Here is my code:
my_function () {
ssh 'user'@$1 <<-END_SSH 2>/dev/null
var=`grep STRING $file.txt | cut -d"'" -f2 | cut -d"(" -f1`
echo "$var"
END_SSH
}
And here is the error:
grep: 0652-033 Cannot open file.txt.
If I execute only the command "grep STRING $file.txt | cut -d"'" -f2 | cut -d"(" -f1" without assigning to $var, everything is successful.
Can you please help me with this issue?
Thank you!
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow