Question

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!

Was it helpful?

Solution

The ` and $ characters are probably being interpreted by the local shell, try escaping them with \

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top