Secondly, you don’t need to quote the “$” sign when you use variable interpolation:
$[desk.n$0]
is sufficient.
The reason why the second function fails, is because FVWM needs to interpolate (that means ‘expand’) the variable, which can only be done via the shell – that’s what piperead is doing here, and returning the entire result back to FVWM.
“I” PipeRead ‘for i in 0 1 2; do
if [ $[desk.n] -ne $i ];
then echo AddToMenu SendToDesk [color=blue]\[/color]$[desk.name$i] ChangeDesk1 $i;
fi; done;’
AddToFunc ChangeDesk
I GotoDesk 0 $0
I PipeRead ‘echo SendToModule FvwmButtons ChangeButton DeskName Title [color=blue]"$"[/color][desk.name$0]’
AddToFunc ChangeDesk1
“I” MoveToDesk 0 $0
“I” PipeRead ‘echo SendToModule FvwmButtons ChangeButton DeskName Title [color=blue]\[/color]$[color=blue]\[/color][desk.name$0[color=blue]\[/color]]’
“I” GotoDesk 0 $0
“I” WarpToWindow 0 0
Functions that don’t work:
AddToFunc ChangeDesk
I GotoDesk 0 $0
I PipeRead ‘echo SendToModule FvwmButtons ChangeButton DeskName Title $[desk.name$0]’
AddToFunc ChangeDesk1
“I” MoveToDesk 0 $0
“I” PipeRead ‘echo SendToModule FvwmButtons ChangeButton DeskName Title [color=blue]\[/color]$[desk.name$0]’
“I” GotoDesk 0 $0
“I” WarpToWindow 0 0
AddToFunc MakeDeskMenu1
“I” DestroyMenu recreate SendToDesk
“I” AddToMenu SendToDesk
“I” PipeRead ‘for i in 0 1 2; do
if [ $[desk.n] -ne $i ];
then echo AddToMenu SendToDesk $[desk.name$i] ChangeDesk1 $i;
fi; done;’
Basically, what you’re seeing is an issue of interpolation. In a function such as yours where you have more than one operand working:
All (foo) PipeRead '... $$[variable] ...'
(as a general example) – there’s often a need to make sure that variable interpolation happens at the right time. So you double-up on dollar signs and the like. Look at some of the other functions posted under this section, for further examples.