Using The If Branch Command - Cisco 11503 - CSS Content Services Switch Administration Manual

Content services switch
Hide thumbs Also See for 11503 - CSS Content Services Switch:
Table of Contents

Advertisement

Using Logical and Relational Operators and Branch Commands

Using the if Branch Command

Cisco Content Services Switch Administration Guide
8-14
To create a branch in a script based on the result of a previous command, use the
if command. If the previous result satisfies the expression in the if statement, the
script engine executes every line between the if and endbranch commands.
Otherwise, the script engine ignores the intervening commands and execution
continues following the endbranch statement.
set MyVar "1"
if MyVar "==" "1"
echo "My variable is equal to ${MyVar}!!!"
endbranch
if MyVar "NEQ" "1"
echo "My variable is not equal to 1 (oh well)."
endbranch
In the example above, the script tests the variable MyVar to see if it is equal to
"1". If it is equal to this value, the echo command between the if command and
the endbranch command is executed. Note that the variable MyVar does not have
the typical variable indicator symbol ($) in front of it. This is because the if
command requires that a constant value or a variable name immediately follow the
command.
An exception to this rule applies when the if command references an array
element. In this case, you must use the normal variable syntax, including the
variable indicator ($) and the braces ({ }). For information on arrays, see
Arrays"
later in this chapter.
For example, the following logical block is valid:
if 12 "==" "${MyVar}"
echo "We made it!"
endbranch
However, this logical block is not valid:
if "12" "==" "${MyVar}"
echo "We made it!"
endbranch
Because the if command expects to see a constant or a variable name (without the
variable indicator), the text string "12" does not satisfy this requirement.
You can also test a variable for a NULL value. For example, enter:
if MyVar
echo "MyVar is equal to ${MyVar}"
endbranch
Chapter 8
Using the CSS Scripting Language
"Using
OL-5647-02

Advertisement

Table of Contents
loading

This manual is also suitable for:

11500 series

Table of Contents