I am writing a script for ssh in a list of machines and comparing a variable with a different value. I'm having a problem (I have a few workarounds, but at the moment I'm just wondering why this method does not work).
VAR=`ssh $i "awk -F: '/^bar/ {print \$2}' /local/foo.txt"`
($ I will be the hostname. Hosts trust, no password provided)
Example foo.txt file:
foo:123456:abcdef
bar:789012:ghijkl
baz:345678:mnopqr
I assume this is a quotation mark problem or \ need somewhere. I tried several methods (different quotes using $ () instead of `` etc.), but it seems that not everything is correct. My script is working correctly using the following:
VAR=`ssh $i "grep bar /local/foo.txt" | awk -F: '{print \$2}'`
As I said, just curiosity, any answer is appreciated.
, : awk , 2- . \, , , "print" .., - .