Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


9.6.3 if statement (branches conditionally)

Syntax 1

if condition-1
then
        processing-a
 [elif condition-2
then
        processing-b]
 [else
        processing-c]
fi

Syntax 2

if condition-1;then
        processing-a
 [elif condition-2; then
        processing-b]
 [else
        processing-c]
fi

Summary

This control statement controls branching based on whether the result of a specified condition is true (0) or false (non-zero).

Description

This statement begins with if and ends with fi. A condition can be any command or a group of commands combined by using operators such as &&, ||, ( ), and { }. If the return code from the command or the command group is 0, execution proceeds to the then clause; if the return code is non-zero, execution proceeds to the else or elif clause.

The elif and else clauses can be omitted, while then and fi must always be specified. Multiple elif clauses can be specified. If the statement is missing any of if, then, or fi, the syntax is invalid and the statement will terminate with an error.

If you specify a semicolon (;) immediately after condition, you can continue specifying the statement on the same line.

Example