Friday, January 06, 2006

"if" command, by Samuel Hoffstaetter

Samuel Hoffstaetter obviously did a lot of work to create the new "if" command. One cool thing about it is that it builds on the landmark IfThen command created by Allen Ormond.

Anyway, here's if in all its glory:


ifthen -value1 ${lt}${gt}${le}${ge}${eq}${ne} -value2 -test EQUAL -then {ifthen -value1 %s -value2 False -test EQUAL -then ${else} -else {ifthen -value1 %s -value2 No -test EQUAL -then ${else} -else {ifthen -value1 %s -value2 0 -test EQUAL -then ${else} -else {ifthen -value1 %s -value2 -test EQUAL -then ${else} -else ${then} -redirect ${follow}} -redirect ${follow}} -redirect ${follow}} -redirect ${follow}} -else {ifthen -value1 %s -value2 ${lt}${gt}${le}${ge}${eq}${ne} -test {ifthen -value1 -value2 ${eq} -test EQUAL -then {ifthen -value1 -value2 ${gt} -test EQUAL -then {ifthen -value1 -value2 ${lt} -test EQUAL -then {ifthen -value1 -value2 ${ge} -test EQUAL -then {ifthen -value1 -value2 ${le} -test EQUAL -then NOTEQUAL -else LESSEQUAL} -else GREATEREQUAL} -else LESS} -else GREATER} -else EQUAL} -then ${then} -else ${else} -redirect ${follow}}


NAME
if - compare two values and return a value based on the result.

SYNOPSIS
if [-lt|gt|le|ge|eq|ne ] [-then ] [-else ] [-follow True|False]

EXAMPLES
if 1 -lt 2 -then yes -else no
(returns "yes" since "1" is less than "2")
if -eq ${var} -then yes -else no
(returns "yes" if var is empty, "no" otherwise)
if True -then yes -else no
(returns "yes")
if False -then yes -else no
(returns "no")
if abc -eq bcd -then http://google.com -else http://yahoo.com -follow True
(returns the Yahoo! webpage)

DESCRIPTION
Either compares two values, or checks for the truth of a value.
All values other than "False", "No", "0" and "" are interpreted
as True.

Permitted comparisons are:
-lt (Less Than)
-gt (Greater Than)
-le (Less than or Equal)
-ge (Greater than or Equal)
-eq (EQual)
-ne (Not Equal)

When checking if a variable is empty, the variable has to
be specified behind the comparison switch:
if -eq ${var} -then yes -else no
The following WILL NOT work:
if ${var} -eq -then yes -else no

If the -follow switch is set to "True", if tries to follow links
that begin with "http://". The default setting for -follow is "False".

AUTHOR
Samuel Hoffstaetter "http://shoffsta.linuxside.org/"
based on "IfThen" by Allen Ormond

0 Comments:

Post a Comment

<< Home