This "if" command is used to condition the processing of file commands on a comparison operation. If the condition is true, the following commands up to the next matching $else, $elseif or $endif are processed, and commands from the $else to the next matching $endif are ignored. Conditional commands may be nested to a depth of thirty-two levels. All condition sets must be properly terminated with balanced $endif statements.
The parameters on this command are used as follows:
x
the first operand, either a literal or @varname.
op
the comparison operation to be performed:
=
equal to
!=
not equal to
>=
greater than or equal to
<=
less than or equal to
>
greater than
<
less than
&
true if binary 'and' of two integers x and y is non-zero
$in
true if x is a substring of y
$sw
true if x has an initial substring (starts with) y
$ew
true if x has a terminating substring (ends with) y
$empty
true if x is an empty string (omit y)
$eq
$ne, $ge, $le, $gt, $lt (see below)
y
the second operand, either a literal or @varname.
For the first seven items in the list above, if both the operands consist only of integers between -263+1 and 263-1, numeric comparisons are performed; otherwise text comparisons are performed.
All text and substring comparisons take account of the case of any alphabetic characters in the values. You can use $set_var to uppercase or lowercase text before comparison if you require a case-blind test.
Double-quotes have no special significance. They are treated like any other character and are not needed to surround values containing spaces. So if you use them on one operand, they should appear on the other operand also.
Conditional commands are not parsed like other commands: instead, first the operator is located, then everything to the left of it is treated as operand 1, and everything to the right is operand 2. Leading and trailing space and tab characters are removed from each operand, and all other characters (including any quote characters) participate in the comparison or other action.
The $in operator has lower precedence than the numeric operators, so this substring comparison may have unexpected results if the operands contain characters = > < & embedded in the value. Note that the $in operator looks for an exact, case-sensitive match of the string to the left of the operator within the string on the right of the operator. Any punctuation and embedded white space participates in this comparison. The $sw and $ew operators behave similarly.
Note that the command must conform to the simple syntax described above and complex expressions and parentheses are not supported. Only the first of the above operations found on the command will be acted on.
If you use numeric values with decimal points, note that 9.9 is bigger than 10.1 when a text comparison is performed. To avoid this problem, use the $eq and similar operation commands which force a correct numeric comparison. The result of comparison of non-valid numeric values with these operations is undefined. Because floating-point decimal values can never be held precisely in the binary format used inside most computer systems, numbers are considered equal if they differ by less than 0.00001.