Chapter 8 Using the CSS Scripting Language
Using Logical and Relational Operators and Branch Commands
8-14
Cisco Content Services Switch Administration Guide
OL-5647-02
Using the if Branch Command
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
“Using
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
Содержание 11500 Series
Страница 16: ...Contents xvi Cisco Content Services Switch Administration Guide OL 5647 02 ...
Страница 18: ...Figures xx Cisco Content Services Switch Administration Guide OL 5647 02 ...
Страница 120: ...Chapter 3 Configuring User Profiles Where to Go Next 3 16 Cisco Content Services Switch Administration Guide OL 5647 02 ...