Re: FVWM: Double-dollars confusion

From: Mikhael Goikhman <migo_at_homemail.com>
Date: Sun, 24 Mar 2002 01:38:18 +0000

On 22 Mar 2002 18:26:08 -0700, Gregg Dameron wrote:
>
> I'm unclear about the rules for double-dollars with bracketed
> parameters. From the man page:
>
> ==================
> Parameter expansion in the + command is different than in
> normal commands. If the command is adding to a function,
> single letter parameters are expanded normally which is
> often not what was intended. To suppress expansion the '$'
> has to be doubled. Parameters enclosed in brackets are pro-
> tected from parameter expansion in these commands so the '$'
> must not be doubled.
> ==================
>
> Suppose I have:
>
> DestroyMenu MyMenu
> AddToMenu MyMenu
> + "My Item" MyFunc $[param1]
>
> ...
>
> DestroyFunc MyFunc
> AddToFunc MyFunc
> + I Exec exec my_script $0 $[param2] $[param3]
>
> where $[paramN] are being updated elsewhere via SetEnv. Is it safe to
> assume that what is true for functions is also true for menus: the
> parameter is expanded at runtime, not at read time, so a single dollar
> is fine?

The special meaning is for function definitions only.

For menus, both $n and $[var.name] are expanded at definition time.
But if at definition time $[MYVAR] does not exist, it is left as is, then
if at run time this variable already SetEnv'd, it is expanded.

The problem only arrises when the variable exists at both definition and
run times and it is different.

> If my "+" command has a PipeRead, do the rules change? An earlier
> posting stated:

No the rules are not changed because of this.

> ==================
> > > > > You can't make calculations in fvwm commands. Use the shell via
>
> > > > > PipeRead instead:
> > > > >
> > > > > Key Left FSTW SCM PipeRead "echo MoveToPage $[$[page.nx]-1]
> $[page.ny]"
> >
> > Add another '$' here:
> >
> > Key Left FSTW SCM PipeRead "echo MoveToPage $$[$[page.nx]-1]
> $[page.ny]"
> > ^^
>
> This would work if the command PipeRead was by itself. But the command
> here is Key. If this line is placed in .fvwm2rc it's always equivalent
> to:
>
> Key Left FSTW SCM PipeRead "echo MoveToPage $$[0-1] 0"
>
> We should escape all dollars for the Key command. The correct line is:
>
> Key Left FSTW SCM PipeRead "echo MoveToPage $$$$[$$[page.nx]-1]
> $$[page.ny]"
> ==================
>
> When is it correct to double-dollar bracketed parameters?

When you don't want them to be expanded. :)

There are different uses. Once you want complex parameters to be expended
at definition time, once at run time.

If you are not sure how to escape variable, write a small function that
uses this variable. In this function you don't need to escape it. Then
instead of writing a variable directly and thinking how to escape it,
call this function and you will not have escape problems, and the variable
will be always expanded at run time.

> Is the quad-dollar guidance unique to Key-with-PipeRead?

No, any command inside another command behaves similarly.

The commands that may get other commands as parameters:

  o Key
  o PointerKey
  o Mouse
  o Stroke
  o Popup (you may optionally give it a click action)
  o Menu (you may optionally give it a double click action)
  o WindowList (the same thing)
  o several module configuration commands, like
    *FvwmBacker: Command
    *FvwmEvent: Cmd
    *FvwmForm: Command
    *FvwmTaskBar: StartMenu
  o AddToMenu (or + after AddToMenu)
  o all conditional commands like Next, Current, All
  o probably more commands

So, if you want to pass literal "$[a]" to shell, you should write
$$$$[a] in all the commands listed above. Hopefully I explained why.

Here is a code that prints a literal dollar '$' to standard error:

  Exec echo "$" # nothing expanded
  Exec echo "$$" # shell gets only one dollar
  Next Exec echo "$$$$" # shell gets only one dollar

Here is a code that prints process number ($$).

  Exec echo "$$$$" # shell gets 2 dollars
  Next Exec echo "$$$$$$$$" # shell gets 2 dollars

Also note that sometimes you may write the same thing in several ways.
Just experiment and see what works.

Regards,
Mikhael.
--
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 Sat Mar 23 2002 - 19:39:00 GMT

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