[Discuss] inventory of most-used programs; bash quoting problem

Greg Rundlett (freephile) greg at freephile.com
Fri May 31 11:08:13 EDT 2013


I was trying to do the following to report on the most used commands (for
each user found in /home).

find /home -maxdepth 2 -name '.bash_history' -exec bash -c 'echo -e
"\n$1\n"; cat "$1" | awk '{ print $1 }' | sort | uniq -c | sort -rn | head
' _ '{}' \;

But I couldn't figure out how to get awk quoting to work inside the bash -c
string literal.  I looked it up, so now I know how to do it. I know it's
been discussed on this list before.  I just throw it out there as a
refresher :-)

Answer: Use these four characters '\'' to represent a single quote (inside
a single quoted string)

(I think you can also use the octal representation of a quote character,
but that's not as easy to remember.)

Greg Rundlett



More information about the Discuss mailing list