[ale] Awk quoting within shell scripts (was X window to foreground)

Greg Freemyer greg.freemyer at gmail.com
Sun Dec 30 00:55:34 EST 2007


Brian,

Did you try awk "/$PID/ {print \$1}"

ie. A combination of double quotes to let the $PID expand and a \ to
stop $1 from expanding?

Greg

On Dec 30, 2007 12:42 AM, Brian Pitts <brian at polibyte.com> wrote:
> 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
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>



-- 
Greg Freemyer
Litigation Triage Solutions Specialist
http://www.linkedin.com/in/gregfreemyer
First 99 Days Litigation White Paper -
http://www.norcrossgroup.com/forms/whitepapers/99%20Days%20whitepaper.pdf

The Norcross Group
The Intersection of Evidence & Technology
http://www.norcrossgroup.com



More information about the Ale mailing list