Re: FVWM: question: Fvwm and Awk: more $1 expansion trouble

From: Dominik Vogt <dominik.vogt_at_gmx.de>
Date: Sun, 28 Jan 2001 16:21:55 +0100

On Sat, Jan 27, 2001 at 10:52:16PM -0330, Neil Zanella wrote:
>
> Hello,
>
> I am trying to have fvwm2 process the following from a config file
> but I am having some difficulties with the variables $1, $2, and $3.
>
> The command is:
>
> /usr/X11R6/bin/xterm -e /bin/sh -c (/usr/X11R6/bin/showrgb | /bin/awk '{
> printf("#%02X%02X%02X\t", $1, $2, $3); for (i = 4; i <= NF; i++)
> printf " " $i; print "" }' | /usr/bin/less)

This does not work because the shell that executes this line
interprets the parentheses and pipe symbols. They have to be
quoted (and then you don't need the parentheses at all. The
positional parameters have to be quoted too:

  /usr/X11R6/bin/xterm -e /bin/sh -c "/usr/X11R6/bin/showrgb | /bin/awk '{
   printf(\"#%02X%02X%02X\t\", \$1, \$2, \$3); for (i = 4; i <= NF; i++)
   printf \" \" $i; print \"\" }' | /usr/bin/less"
  
> (the parentheses are not working outside fvwm for some reason so you can
> enter the above without parentheses at a shell prompt and have no less)
>
> Note: the following works from a shell prompt (all one one line):
>
> /usr/X11R6/bin/showrgb | /bin/awk '{
> printf("#%02X%02X%02X\t", $1, $2, $3); for (i = 4; i <= NF; i++)
> printf " " $i; print "" }' | /usr/bin/less
>
> Now I tried the following and a few other things but
> they did not work (although the $i works fine)...

The easiest way to make it work is to put it in a script. Then
you don't have to worry about fvwm's quoting.

> + "RGB" "I" Exec /usr/X11R6/bin/xterm-e /bin/sh -c
> "(/usr/X11R6/bin/showrgb | /bin/awk '{ printf(\"#%02X%02X%02X\t\", $$$$1,
> $$$$2, $$$$3); for (i = 4; i <= NF; i++) printf \" \" \$i; print \"\" }' |
> /usr/bin/less)"

Um, did you try to add this to a function or a menu? If it's a
menu, the line must begin with

  + "RGB" Exec

if it's a funtion it must start with

  + "I" Exec

But you used

  + "RGB" "I" Exec

8-)

Also, the command must be "xterm -e" not "xterm-e". And again,
the '$1' must be quoted (e.g. with a backslash):

  + I Exec /usr/X11R6/bin/xterm -e /bin/sh -c
  "/usr/X11R6/bin/showrgb | /bin/awk '{ printf(\"#%02X%02X%02X\t\",
  \$$$$1, \$$$$2, \$$$$3); for (i = 4; i <= NF; i++)
  printf \" \" $i; print \"\" }' | /usr/bin/less"

> Could someone please point what went wrong?

Just to give you an idea why this is so complicated: This line
is executed as a normal fvwm command that adds a new item to a
complex function that executes an xterm command that starts a
shell to run a script that runs a pipe which includes an awk
script that prints positional parameters with a format mask.
If my count is correct, quotes, '|' symbols and '$' are
interpreted up to eight times by at least four different parsers
(fvwm, sh, awk and xterm) in this chain. Each of these parsers
has a different idea how things work. In this situation it is
almost always better to get these commands straight on the command
line, then put them in a shell script and execute the script from
the function.

Bye

Dominik ^_^ ^_^

--
Dominik Vogt, dominik.vogt_at_gmx.de
Reply-To: dominik.vogt_at_gmx.de
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_fvwm.org.
To report problems, send mail to fvwm-owner_at_fvwm.org.
Received on Sun Jan 28 2001 - 10:00:50 GMT

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:51 BST