[ale] Awk quoting within shell scripts (was X window to foreground)
Brian Pitts
brian at polibyte.com
Sun Dec 30 00:42:33 EST 2007
The wmctrl program is packaged for debian and ubuntu and seems pretty
cool. I was trying to write a script with it when I ran into some issues
with shell quoting and awk.
#!/bin/sh
for PID in $(pgrep $1)
do
for WINDOW in $(wmctrl -lp | awk '/$PID/ {print $1}')
do
wmctrl -iR $WINDOW
done
done
The above shows what I tried to accomplish: given a process name as the
argument, for every PID it has raise the associated windows. Of course
it doesn't work since $PID isn't expanded within single-quotes. However,
I can't make awk work with double-quotes no matter how creative I get.
My workaround is
wmctrl -lp | grep $PID | cut -d " " -f 1
but I'd love to know how to do it right with awk. Suggestions?
-Brian
More information about the Ale
mailing list