awk - bash command quoted by single quote -
i need find process string matching, , kill it, need in 1 line in script file: here's tried:
'kill $(ps -ef|grep xxx|grep -v grep | awk '{print $2 }' )'
"kill $(ps -ef|grep xxx|grep -v grep | awk '{print $2 }' )"
first 1 didn't work because of nested single quote, second 1 didn't work because $2 taken parent script argument 2 parent script. how do this?
the easiest way accomplish task is:
pkill xxx
(which you'll find in debian/ubuntu world in package procps
, if don't have installed.) might need use pkill -f xxx
, depending on whether xxx part of process name or argument, case script execution.
however, answer more general question shell-quoting, if need pass string
kill $(ps aux | grep xxx | grep -v grep | awk '{print $2}')
as argument, need use backslash escapes:
bash -c "kill \$(ps aux | grep xxx | grep -v grep | awk '{print \$2}')"
or, can paste several quoted strings:
bash -c 'kill $(ps aux | grep xxx | grep -v grep | awk '"'"'{print $2}'"'"')'
personally, find first 1 more readable ymmv.
you can backslash escape few characters inside double-quoted string: $
, "
, \
, newline , backtick; , inside single-quoted string backslash backslash. however, that's enough let type anything.
Comments
Post a Comment