The Form and Menu Language

Conditional statements

The Form and Menu Language provides a conditional statement for use within backquoted expressions that has the following syntax:

   if list then list [ elif list then list ] . . . [ else list ] fi
where list is an optional newline, followed by a sequence of one or more FMLI statements, each of which must end with a semicolon.

Like conditional statements in the UNIX system shell language, the list following if is executed, and if the last command in the list has a zero exit status, then the list that follows then is executed. However, if the list following if has a non-zero exit status, the list following else will be executed. Multiple tests can be executed by using the elif clause. Conditional statements may be nested.

Output of a statement executed within an FMLI conditional construct can be redirected to a file specified after the statement.

The exit status of the conditional statement is the exit status of the last command executed in any then clause or else clause. If no such command was executed, the conditional statement returns a zero exit status.

NOTE: The FMLI conditional statement differs from the UNIX shell language conditional statement in some respects.

The UNIX shell language allows either a newline, a semicolon, or both, to end a statement, whereas FMLI only allows a semicolon.

Output of statements executed within an FMLI conditional construct cannot be piped to a statement following the fi of the construct. Similarly, output redirection to a file specified after the fi of the construct does not work.

An FMLI conditional statement cannot occur following the && or || operators in a given backquoted expression.

(See ``Built-in utilities'', CM test 1 , and fmlexpr(1fmli).)

Conditional statements are useful when only one of several actions is appropriate, based on user input. For example, assume that you have defined a form in which a user must enter either 1 or 2 in the first field to display one of two appropriate text frames. A conditional statement can be used to display an appropriate error message via the use of the descriptor invalidmsg, when the user enters an invalid response:

invalidmsg=`if [ $F1 -gt 2 ];
echo "APPLID:nnn: Selection code has to be less than 3";
echo "APPLID:nnn: Selection code has to be more than 0";

where $F1 (an FMLI built-in variable) evaluates to the current value of the first field, APPLID is the name of your application, and nnn is the message sequence number.

Another conditional statement can be used to open the text frame requested by the user. The descriptor done in the same form definition file would be defined as follows:

done=`if [ $F1 = 1 ];
then echo "open text dir.explain";
else echo "open text file.explain";

Next topic: Signal handling
Previous topic: Overview of the built-in utilities

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004