What I want to do:
I want a function that mounts a device if its unmounted and unmount the device if its already mounted. Seems to be Simple…
But I don’t know how to make this wiht only one function! I don’t know any way to make someting like if ( dev == mounted) {umount dev}
So it is a means of using the $SHELL to evaluate conditional commands, and generate Fvwm commands based on the output. A classic example is using PipeRead to generate dynamic menus. For instance I have a function which adds colorset information to a menu:
AddToFunc FuncFvwmMenuColorset
+ I DestroyMenu recreate FvwmMenuColorset
+ I PipeRead 'echo "AddToMenu FvwmMenuColorset Colorsets Title"'
+ I PipeRead 'echo \+ \\"Reset\\" Function ChangeStyle "1 fg white, bg #c06077";
echo \\+ \\"\\" Nop'
+ I PipeRead 'while read l; do echo +\"${l/*bg /\ }\" Function ChangeStyle "$l";
done < ~/.fvwm/colorsets'
does only send the command to the shell and the output isn’t used…
and the command it selfs is a logical OR (like in C/C++) so if mount $0 don’t work (because it’s already mounted) it’s 0 so he tries umount §0…
I’m right?
In this example, we’re not actually bothering with the output – fvwm makes no use of it. So what is run, is done at the $SHELL level. What happens is this:
+ I PipeRead 'mount $0 || umount $0'
$0 is a positional parameter for function – used in the context of FVWM only, in this instance. By positional, I mean it takes on whatever value was passed to the function. $0 is the first value.
So what happens is that when we invoke the function:
ToggleWindow /mnt/foo
$0 is replaced with /mnt/foo. When the function encounters a PipeRead, that simply passes the resulting command to the shell, expanding $0 as it goes, so that actually the shell sees:
mount /mnt/foo || umount /mnt/foo
And yes, && and || are conditional. They’re slightly different to how C/C++ uses them though. In bash, it works like this. Let’s use that mount command from earlier:
mount $0 || umount $0
“If the mount command fails (i.e., ‘||’), then do what is to the left of ‘||’”. Similarly you can negate that:
command && echo worked
… for instance says "if ‘command’ worked (&&) do what’s on the right (in which case that would print ‘worked’).
Note that this is to do more with shell semantics than it is with Fvwm…