HP OpenVMS DCL Dictionary
Tests the value of an expression and, depending on the syntax
specified, executes the following:
- One command following the THEN keyword if the expression is true
- Multiple commands following the $THEN command if the expression is
- One or more commands following the $ELSE command if the expression
$ IF expression THEN [$] command
$ IF expression
$ THEN [command]
. . .
$ [ELSE] [command]
. . .
HP advises against assigning a symbolic name that is already a DCL
command name. HP especially discourages the assignment of symbols such
as IF, THEN, ELSE, and GOTO, which can affect the interpretation of
Defines the test to be performed. The expression can consist of one or
more numeric constants, string literals, symbolic names, or lexical
functions separated by logical, arithmetic, or string operators.
Expressions in IF commands are automatically evaluated during the
execution of the command. Character strings beginning with alphabetic
characters that are not enclosed in quotation marks (" ") are
assumed to be symbol names or lexical functions. The command language
interpreter (CLI) replaces these strings with their current values.
Symbol substitution in expressions in IF commands is not iterative;
that is, each symbol is replaced only once. However, if you want
iterative substitution, precede a symbol name with an apostrophe (') or
The command interpreter does not execute an IF command when it contains
an undefined symbol. Instead, the command interpreter issues a warning
message and executes the next command in the procedure.
For a summary of operators and details on how to specify expressions,
see the OpenVMS User's Manual.
Specifies the DCL command or commands to be executed, depending on the
syntax specified, when the result of the expression is true or false.
The IF command tests the value of an expression and executes a given
command if the result of the expression is true. The expression is true
if the result has an odd integer value, a character string value that
begins with the letters Y, y, T, or t, or an odd numeric string value.
The expression is false if the result has an even integer value, a
character string value that begins with any letter except Y, y, T, or
t, or an even numeric string value.
$ COUNT = 0
$ COUNT = COUNT + 1
$ IF COUNT .LE. 10 THEN GOTO LOOP
This example shows how to establish a loop in a command procedure,
using a symbol named COUNT and an IF statement. The IF statement checks
the value of COUNT and performs an EXIT command when the value of COUNT
is greater than 10.
$ IF P1 .EQS. "" THEN GOTO DEFAULT
$ IF (P1 .EQS. "A") .OR. (P1 .EQS. "B") THEN GOTO 'P1'
$ WRITE SYS$OUTPUT "Unrecognized parameter option ''P1' "
$ A: ! Process option a
$ B: ! Process option b
$ DEFAULT: ! Default processing
This example shows a command procedure that tests whether a parameter
was passed. The GOTO command passes control to the label specified as
If the procedure is executed with a parameter, the procedure uses that
parameter to determine the label to branch to. For example:
When the procedure executes, it determines that P1 is not null, and
branches to the label A. Note that the EXIT command causes an exit from
the procedure before the label B.
$ SET NOON
$ LINK CYGNUS,DRACO,SERVICE/LIBRARY
$ IF $STATUS
$ RUN CYGNUS
$ WRITE SYS$OUTPUT "LINK FAILED"
This command procedure uses the SET NOON command to disable error
checking by the command procedure. After the LINK command, the IF
command tests the value of the reserved global symbol $STATUS. If the
value of $STATUS indicates that the LINK command succeeded, then the
program CYGNUS is run. If the LINK command returns an error status
value, the command procedure issues a message and exits.
$ if 1 .eq. 1
$ if 2 .eq. 2
$ write sys$output "Hello!"
This example shows how to use a nested IF structure.