Messy bash variable
Posted
by Kyle
on Stack Overflow
See other posts from Stack Overflow
or by Kyle
Published on 2010-03-18T18:19:20Z
Indexed on
2010/03/18
18:21 UTC
Read the original article
Hit count: 320
I'm writing a script to ssh in to a list of machines and compare a variable to another value.. I've run into a problem (I have a couple workarounds, but at this point I'm just wondering why this method isn't working).
VAR=ssh $i "awk -F: '/^bar/ {print \$2}' /local/foo.txt"
($i would be a hostname. The hosts are trusted, no password prompt is given) Example of foo.txt:
foo:123456:abcdef bar:789012:ghijkl baz:345678:mnopqr
I'm assuming it's a problem with quotes, or \'s needed somewhere. I've tried several methods (different quoting, using $() instead of ``, etc) but can't seem to get it right. My script is working correctly using the following:
VAR=ssh $i "grep bar /local/foo.txt" | awk -F: '{print \$2}'
Like I said, just a curiousity, any response is appreciated.
© Stack Overflow or respective owner