User guide
CLI Scripting Web Services, CLI Scripting and OpenFlow
page 11-20 OmniSwitch AOS Release 7 Switch Management Guide March 2015
CLI Scripting
The AOS CLI relies on Bash scripting, it can be leveraged for creating CLI scripts without the need for an
external tool. This Bash-based CLI allows users to perform high-level scripting work if necessary as given
in the example below. This example illustrates simple example that creates multiple, non-contiguous,
through the use of loops and variables. For instance:
#!/bin/bash
for vlanid in 1 2 3 4 10 15; do
vlan $vlanid
done
Since the existing CLI infrastructure is being leveraged, the CLI's own security model is followed (Bash
already authorizes commands based on partition management).
Quoting and escaping
Quotes (') and double quotes (") are used to enclose literal strings. Single quotes provide the most literal
guard whereas double quotes will expand "$" variables. Due to this behaviour, entering the text below will
display "Hello" on a first row of the terminal, followed by "World" on the next row.:
echo 'Hello,<Return>
World'<Return>
Because literal mode single quotes were used pressing <Return> simply added that key's code to its literal
string. Literal mode was exited with the closing single quote, which is why the second <Return> submit-
ted the command to Bash.
Backslash (\) is a continuation character. This means that the current line is continued on the next line.
The example below will display “Hello World” on a single row:
echo Hello,\<Return>
World<Return>
HEREDOC (<<) is a form of I/O redirection that will feed a whole block to executables. HEREDOC
takes a parameter and that parameter will be used by Bash to find the end of this pseudo I/O stream.
For instance, entering as root:
wall <<EOB<Return>
Hello,<Return>
World<Return>
EOB<Return>
will display the following on every logged in user's terminal:
Broadcast message from root (<Date>):
Hello,
World
The example above indicated to Bash a block of text was begun and that it would end when EOB was
encountered at the beginning of a line.