Cisco 11503 Administration Guide - Page 282
Using the if Branch Command
UPC - 746320664958
View all Cisco 11503 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 282 highlights
Using Logical and Relational Operators and Branch Commands Chapter 8 Using the CSS Scripting Language Using the if Branch Command 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 "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 Cisco Content Services Switch Administration Guide OL-5647-02