Top
Systemwalker Operation Manager V17.0.1 Reference Guide

15.2.12 if-else (Perform Conditional Branching)

Description

Executes scripts on a conditional basis.

Synopsis

if {expr1} [then] {body1} [elseif {expr2} [then] {body2}]
[elseif ...] [else {bodyN}]

Options

expr

Defines the conditional expression. For a numeric value, 0 is false and anything other than 0 is true. For a string value, true or yes is true and false or no is false. Do not put a comment into conditional expression.

Condition operators available for conditional expressions

!

NOT

< , > , <= , >= , == , !=

Comparison

&& , ||

Logical AND, logical OR

body

The script command executed when the condition is true. Two or more commands can be written by being separated by line breaks or semicolons.

Caution

Keywords (if, then, elseif, and else) must be separated from "{" by blanks or tabs. If "then" is omitted, "}" must be separated from "{" by blanks or tabs.

When inserting a line break in other than body such as between "}" and "{", add backslash sign (\) to the last of the line to indicate continuation.

Example

The following example determines whether the value of variable a is greater than 0 or not and displays the result.

if {$a > 0} {
      puts "a > 0"
} else {
      puts "a <= 0"
}

Execution Results/Output Format

Either of the following lines is output depending on the value of a.

a > 0

or,

a <= 0