[ale] Awk quoting within shell scripts (was X window to foreground)
List
lst at wiencko.net
Sun Dec 30 01:02:54 EST 2007
Escape the $ inside the awk script: ... awk "/$PID/ {print \$1}"
... ought to fix it. Otherwise the shell expands the $1.
Brian Pitts 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
More information about the Ale
mailing list