Cisco 11503 Administration Guide - Page 294
Capturing User Input
UPC - 746320664958
View all Cisco 11503 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 294 highlights
Capturing User Input Chapter 8 Using the CSS Scripting Language Capturing User Input To capture user input in a variable, use the input command. You can use this command to create a script to assist users in setting up configuration files or preparing a CSS in some predefined way. For example, enter: ! Ask the user for his/her full name echo "What is your full name?" input FULL_NAME echo "Hello ${FULL_NAME}!" In the example above, notice that the input command has a variable argument called FULL_NAME. Notice that you do not need to set FULL_NAME prior to the input command. The command creates the variable and fills it with the data that the user supplies. Also, note that the user's input is terminated by a carriage return. A user can enter any alphanumeric characters. If a user presses only the Enter key and does not type any characters, then the script creates the variable with a NULL value. This allows you to test the user input to verify that the user typed something. In the following example, the script continues to ask the user the same question until the user types "y". echo -n "\please enter the character 'y' to exit." input DATA while DATA "NEQ" "y" echo -n "Please enter the character 'y' to exit: " input DATA echo "\n" endbranch In the example above, notice the use of the echo command with the -n parameter. This allows you to prompt the user with a message without forcing a new line at the end of the sentence so that the user's data appears on the same line as the echo command output. In the echo command quoted string, you can embed "\n", a C-programming style character that puts a line feed in the output to make it more readable. 8-26 Cisco Content Services Switch Administration Guide OL-5647-02