Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to escape the ' in this command for ssh exec

grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 |awk -F= '{print $2}'

How do I escape that?

I currentl y have this which does not work

ssh host 'grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 |awk -F= '{print $2}''

nor does this

ssh host 'grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0 |awk -F= \'{print $2}\''

thanks, Dean

share|improve this question
    
You cannot escape single quotes within a single quoted string. –  glenn jackman Aug 27 '12 at 21:19
add comment

2 Answers

never mind, I just found this awesome snippet which is way cool so I don't need to keep asking how to escape this or that...

ssh user@serverB <<\EOF
your sql query....
.....
.....
EOF
share|improve this answer
add comment

Assuming you don't need to do any substitution (parameter, command, etc) inside the string, you can use $'...' quoting:

ssh user@serverB $'grep str file | awk \'{print $2}\''

As a side note, you can usually replace grep/awk pipelines with a single call to awk:

ssh user@serverB $'awk \'/str/ {print $2}\' file'
share|improve this answer
    
need to escape the $ if you use double quotes around the awk body –  glenn jackman Aug 27 '12 at 21:19
    
Right; that double-quote is left over from a different approach I was going to try, though. Removing it entirely to make a correct call to awk inside $'...'. –  chepner Aug 27 '12 at 21:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.