Checking and Using environment variables in FVWM

Hi all:

I’ve read through the forum on everyone’s posts on using setenv and unsetenv to set and change environment variables, but I dont’ know what syntax to use to actually look at the env variable and then to act on it.

for example, I want to check an environment variable, and if it == 1, then I want to call FuncFoo_1 and reset the var to == 2, if it is already ==2, I want to call FuncFoo_2, and then reset the variable to 1… kind of an isolating thing…

the Pseudo code would look like the following:

if(envVar == 1)
{
   envVar = 2;
   FuncFoo_1();
}
else
{
    envVar = 1;
    FuncFoo_2();
}          

I know it’s stupid, but I am unsure how to check that variable’s value…
would something like

+ I Test ($[my_env_var]) FuncFoo_1

let me check the current value? I have tried the above syntax, but am unsure if it is even close to right…

thanks in advance,
Skender

with v2.5.14 you can use the EnvIsSet and EnvMatch test conditions to test variables.

Indeed. But for those that don’t yet have that version (and who can blame them), what you need to remember, Skender, is that “SetEnv” simply exports the variable. So the way you can check that it is set, is to use PipeRead:

+ I PipeRead '[ $FOO = "value" ] && echo some_fvwm_command'

– Thomas Adam

I apparently suck at writing Bash Scripts.

Does anything look wrong in the script below?

It just needs to toggle the ENV_VAR.

+ I PipeRead `[ "$[ENV_VAR]" == "True" ] &&\
   echo 'SetEnv ENV_VAR False' ||\
   echo 'SetEnv ENV_VAR True'`

it doesn’t seem to be doing anything. The ENV_VAR doesn’t seem to change…

  • Skender

Remove the single quotes around ‘echo SetEnv …’ so that the whole thing looks like this:

+ I PipeRead `[ "$[ENV_VAR]" == "True" ] &&\
   echo SetEnv ENV_VAR False ||\
   echo SetEnv ENV_VAR True`

– Thomas Adam

9 years later… the same problem here… :slight_smile:

I want to reset also an ENV_VAR using a Menu.

The menu-entry is (not in a Function)

  • $[mpd_host] SetEnv $mpd_host 169.254.0.2

but $mpd_host is next time the same as before. It doesn’t change to 169.254.0.2…

What is wrong?

jakob

[EDIT]

Solved for me in viewtopic.php?f=38&t=2954

[/EDIT]