| Purpose: |
Evaluates conditional operations in a script file. |
| Format: |
IF [NOT] [WARN | ERROR | FAIL] [<string-a> EQ | GT | GE <string-b>]
[VAL] [EXISTS <filename>]
|
| Template: |
NOT/S, WARN/S, ERROR/S, FAIL/s, EQ/K, GT/K, GE/K, VAL/S, EXISTS/K |
| Path: |
Internal |
|
|
In a script file, IF, when it conditional is true, carries out all of the subsequent commands until an ENDIF
or ELSE command is found. IF must be used in conjunction with ENDIF,
however, ELSE is optional. When the conditional is not true, execution skips to directly to the
ENDIF or to an ELSE. The conditions and commands in IF and
ELSE blocks can span more than one line before their corresponding ENDIFs.
Nested IFs jump to the matching ENDIF.
The additional keywords are as follows:
| NOT |
Reverses the interpretation of the result. |
| WARN |
True if previous return code is greater than or equal to 5. |
| ERROR |
True if previous return code is greater than or equal to 10; only available if FAILAT is set to greater than 10.
|
| FAIL |
True if previous return code is greater than or equal to 20; only available if FAILAT is set to greater than 20.
|
| <a> GT <b> |
True if the text of <a> is greater than the text of <b> (disregarding case). Use NOT GT for less than or
equal to.
|
| <a> GE <b> |
True if the text of <a> is greater than or equal to the text of <b> (disregarding case). Use NOT GE for less
than.
|
| <a> EQ <b> |
True if the text of <a> is identical to the text of <b> (disregarding case). Use NOT EQ for not equal.
|
| VAL |
Specifies a numeric comparison. |
| EXISTS <file> |
True if the file exists. |
If more than one of the three condition-flag keywords (WARN, ERROR, FAIL) are given, the one with the lowest value is used.
You can use local or global variables with IF by prefacing the variable name with a $ character.
Example 1:
IF $Language EQ "english"
ECHO "Hello"
ENDIF
IF $Language EQ "french"
ECHO "Bonjour"
ENDIF
IF $Language EQ "german"
ECHO "Hallo"
ENDIF
The global variable Language is tested and an appropriate greeting is displayed for just 3 languages.
Example 2:
IF EXISTS Work/prog
TYPE Work/Prog HEX
ELSE
ECHO "Work/Prog is not here"
ENDIF
AmigaDOS displays the file Work/Prog if it exists in the current directory, otherwise it displays the message and continues
after the ENDIF.
Example 3:
IF ERROR
SKIP errlab
ENDIF
ECHO "No error"
LAB errlab
If the previous command produces a return code greater than or equal to 10 AmigaDOS skips over the ECHO command to
the errlab label.
See also: ELSE, ENDIF, EXECUTE,
FAILAT, LAB, QUIT,
SKIP
Return to Commands Selection
Disclaimer: Amiga Auckland have prepared the above information for the use of its members based on our experiences
and as such is subject to revision at any time. Amiga Auckland cannot guarantee any of the information and cannot be held
accountable for any issues that may result from using it.
|