[SOLVED] evaluate function parameter

Hi to all.
I searched in the man pages and in the forum too, before posting this basic question… :blush:

I played without success wiht Test and TestRc commands.

I’d like to write a function like this:
pseudo code:

function exec_progXYZ( mode ) { if( mode == 'A' ) { exec XYZ } elseif ( mode == 'B' ) { exec XYZ -switch-1 -switch-2 ... } else { exec XYZ -switch-10 } }
Can someone help?

Thanks in advance…

The problem here though, is that the TestRc conditional only works by evaluating the last run command within the function. What you need to do here is test for the value being passed into the function, and depending on the value run whatever the negation of that is.

You want something like this:

DestroyFunc some_func
AddToFunc   some_func
+ I PipeRead `[ "$0" == "modea" ] || echo "Exec exec exec XYZ -switch-10" ]`
+ I TestRc (Match) Exec exec some_command
+ I PipeRead `[ "$0" == "modeb" ] && echo "exec XYZ -switch-1 -switch-2" ]`

some_func modea

The above maps onto your function by the following logic. I’ve put line numbers in for clarity:

function exec_progXYZ( mode ) { 1 if( mode == 'A' ) 2 { 3 exec XYZ 4 } elseif ( mode == 'B' ) { 5 exec XYZ -switch-1 -switch-2 ... 6 } else { 7 exec XYZ -switch-10 8 } 9 }

I’ll take each line of the function above and detail it.

+ I PipeRead `[ "$0" == "modea" ] || echo "Exec exec exec XYZ -switch-10" ]`

This line runs lines 1, 6, 7, and 8 in your example. If the value passed to the function is not equal to “modea”, then execute said command.

+ I TestRc (Match) some_command

This line matches with lines 2,3. If it is true within the last PipeRead
statement that $0 did equal “modea” then it has to run this line.

+ I PipeRead `[ "$0" == "modeb" ] && echo "Exec exec XYZ -switch-1 -switch-2" ]`

Finally, this line does the same as the fist PipeRead statement, except that as there is no further else clause we can just evaluate to whether the mode is equal to “modeb” and to run that command, else silenty drop the negation of that.


– Thomas Adam

Thanks Thomas Adam, your help is always valuable. :smiley:

I made this post 'cause I’d like to have one function
to display a transparent and non transparent aterm.

By default my aterm is set to transparent (.Xresources),
so with your help I made the following function:

[code]DestroyFunc ExecTermFunc
AddToFunc ExecTermFunc

  • I PipeRead ‘[ “$0” == “opaque” ] && echo “Exec exec aterm +tr +trsb”
    || echo “Exec exec aterm”’[/code]

That I use with this bindings:

Key F1 A M ExecTermFunc Key F2 A M ExecTermFunc opaque

Thanks again, :wink: