uCon HomePage

Script Cmd: IF


IF [-b:fv] {var1} {test} [var2] {ACTION} [else ACTION]

Options:

-b   specify base (default to follow rules of strtol()).
-f    use floating point (double) as the base type for var1 & var2 (default is long).
-v   verbosity on.


Conditional test. Used to support conditional branching within the script.

Valid tests are:

Numerical comparison:
lt        less than
gt        greater than
le        less than or equal to
ge        greater than or equal to
eq        equal to
ne        not equal to

Logical comparison:
or        var1 ORed with var2 is nonzero
and       var1 ANDed with var2 is nonzero
xor       var1 XORed with var2 is nonzero

String comparison:
sec       string equal (case insensitive)
seq       string equal
sne       string not equal
contains  var1 contains var2

For the following cases, var2 is omitted:
ismac     does var1 meet MAC address syntax (XX:XX:XX:XX:XX:XX)?
isip      does var1 meet IP address syntax (nnn.nnn.nnn.nnn)?
ishex     are all characters in var1 hexadecimal notation (0-9,a-f,A-F,x,X)?
isdec     are all characters in var1 decimal (0-9)?
isfloat   are all characters in var1 basic floating point notation (0-9,'.')?

(If you have suggestions for other useful tests, let me know.)

Valid actions are:

EXIT
RETURN
CONTINUE
GOTO {tag}
GOSUB {tag}
RUN {scriptname}

Example using 'ismac' comparison type:

DIALOG Q_AND_A "Please enter the MAC address"
SET MAC $DIALOG
IF ${MAC} ismac CONTINUE else GOTO BAD_MAC
ECHO OK!
EXIT

# BAD_MAC:
ECHO Invalid MAC address syntax
EXIT

Refer to examples on the main scripting page for more examples of the IF command.