IF (_expression) THEN


This is a script command and operates only in scripts when scripting is enabled with the following command: enable cli scripting {permanent}.


Optionally executes a code block based on the condition supplied.

Syntax Description

expression Specifies the condition for which the statements should be executed.
statements Actions to be executed when the specified conditions are met.



Usage Guidelines

This command is usually followed by statements that are executed if the condition evaluates to true.

It can also be followed by an ELSE block, which is executed if the condition evaluates to false.

The IF construct should be terminated by an ENDIF command.

The _expression must be enclosed in parentheses.

The IF construct can be nested inside other IF and WHILE constructs. Nesting is supported up to five levels. If there is incorrect nesting of IF conditions, an error message is displayed. If a user tries to execute more than five nested IF conditions, an error message is displayed.

The operators mentioned in Using Operators can be used in an _expression in an IF condition.

You can insert comments by using a number sign (#).


The following example executes the show switch command if the value of the variable is greater than 2 and executes the show vlan command otherwise:

IF ($x > 2) THEN

    show switch


    show vlan



This command was first available in ExtremeXOS 11.6.

Platform Availability

This command is available on ExtremeSwitching X435, X440-G2, X450-G2, X460-G2, X465, X590, X620, X670-G2, X690, X695, X870, 5320, 5420, and 5520 series switches.