Cisco 11503 Administration Guide - Page 295
Using Command Line Arguments
UPC - 746320664958
View all Cisco 11503 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 295 highlights
Chapter 8 Using the CSS Scripting Language Using Command Line Arguments Using Command Line Arguments The CLI allows a user to pass command line arguments as quoted text to a script using the script play command (see "Playing a Script"). Use the special reserved ARGS variable to access the command line arguments that a user passed to a script. To print out all the arguments that a user passed to a script, enter: echo "You passed the arguments: ${ARGS}" If you want to access each argument individually, you can use the ARGS variable as an array, where each argument passed on the command line is separated by spaces. For example, enter: echo "Your first argument passed is: ${ARGS}[1]" The script below (called NameScript) prints a user's first and last names. The script requires that the user pass his/her first and last name (in that order) in quoted text to the script. For example, enter: !no echo if ${ARGS}[#] "NEQ" "2" echo "Usage: NameScript \'First_Name Last_Name\'" exit script 1 endbranch echo "First Name: ${ARGS}[1]" echo "Last Name: ${ARGS}[2]" exit script 0 This script first tests to see if the user passed any arguments. If the user did not pass exactly two arguments, then the script prints usage information to the screen and exits. If the user passed two arguments, the script assumes that the first argument is the user's first name and the second argument is the user's last name. Finally, the script prints the user's first name and last name to the screen. For example, to play NameScript, enter: script play NameScript "John Doe" The output is: First Name: John Last Name: Doe OL-5647-02 Cisco Content Services Switch Administration Guide 8-27