UNIX for OpenVMS Users, Second Edition

Section 10.8: Flow Control

10.8 Flow Control

The statements IF-THEN-ELSE-ENDIF, GOSUB-RETURN, CALL, and GOTO provide flow control in OpenVMS command procedures. The UNIX C shell also offers if and goto and the additional statements while, foreach, break, continue, switch, breaksw, and shift to control the logical flow of a shell script. The Korn shell provides if, while, until, for, break, continue, case, select, and shift. As with DCL command procedures, both C shell and Korn shell allow you to exert flow control in response to error conditions (see Section 10.8.12).

10.8.1 if (C and Korn shells)

The if statement provides a one- or two-way conditional branch. You can nest if statements, as the more complex examples in Section 10.11 show.

VMS

UNIX (C shell)

Form:

$ <b class="bold">IF</b> <b class="bold"><i class="emphasis">expression</i></b>$ <b class="bold">THEN</b><b class="bold"><i class="emphasis">command(s)</i></b>$ <b class="bold">ELSE</b><b class="bold"><i class="emphasis">command(s)</i></b>$ <b class="bold">ENDIF</b>
% <b class="bold">if (<span class="emphasis"><iexpression</i></span>) then</b><b class="bold"> </b><b class="bold">else</b><b class="bold"> </b><b class="bold">endif</b>

Form:

$ <b class="bold">IF</b> <b class="bold"><i class="emphasis">expression</i></b> <b class="bold">THEN</b> <b class="bold"><i class="emphasis">command</i></b>

Example:

$ <b class="bold">TYPE TEST.COM</b>$! Report a file's executable status$ INQUIRE A "Enter filename:"$ IF (F$PARSE(A,,,"TYPE") .EQS. ".EXE")$ THEN$ WRITE SYS$OUTPUT A," is-executable"$ ELSE$ WRITE SYS$OUTPUT -A," is not-executable"$ ENDIF
% <b class="bold">cat test_script</b># Report a file's executable statusecho -n "Enter filename:"set a= $

Example:

$ <b class="bold">TYPE TEST.COM</b>$! Display a non-empty file$ IF (F$FILE_ATTRIBUTES-(P1, "EOF") .EQ. 0) THEN GOTO EMPTY$ TYPE/PAGE 'P1'$ EXIT$ EMPTY:...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: DC-DC Converter Chips
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.