An EHS script can contain local (static) variables and use some basic .if and .set commands. The use of variables with .if and .set commands in an EHS script adds more logic to EHS scripting and allows the reuse of a single EHS script for more than one trigger or action.
Both the passed-in and local variables can be used in the EHS script either as part of the CLI commands or as part of the .if or .set commands.
The following applies to both CLI commands and .if or .set commands.
Using $X (without using single or double quotes) replaces the variable X with its string or integer value.
Using ‟X” (with double quotes) means the literal string X.
Using ‟$X” (with double quotes) replaces the variable X with its string or integer value.
Using 'X' (with single quotes) means the literal string X.
Using ‛$X’ (with single quotes) does not replace the variable X with its value but means the literal string $X.
In summary:
All characters within single quotes are interpreted as string characters.
All characters within double quotes are interpreted as string characters except for $, which replaces the variable with its value (for example, shell expansion inside a string).
Some supported shell command scenarios are as follows (the commands are pseudo commands):
.if $string_variable==string_value_or_string_variable {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if ($string_variable==string_value_or_string_variable) {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if $integer_variable==integer_value_or_integer_variable {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if ($integer_variable==integer_value_or_integer_variable) {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if $string_variable!=string_value_or_string_variable {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if ($string_variable!=string_value_or_string_variable) {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if $integer_variable!=integer_value_or_integer_variable {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.if ($integer_variable!=integer_value_or_integer_variable) {
CLI_commands_set1
.} else {
CLI_commands_set2
.} endif
.set $string_variable = string_value_or_string_variable
.set ($string_variable = string_value_or_string_variable)
.set $integer_variable = integer_value_or_integer_variable
.set ($integer_variable = integer_value_or_integer_variable)
where:
CLI_commands_set1 is a set of one or more CLI commands
CLI_commands_set2 is a set of one or more CLI commands
string_variable is a local string variable
string_value_or_string_variable is a string value/variable
integer_variable is a local integer variable
integer_value_or_integer_variable is an integer value/variable
A maximum of 100 local variables per EHS script is imposed. Exceeding this limit may result in an error and only partial execution of the script.
When a set statement is used to set a string_variable to a string_value, the string_value can be any non-integer value with optional single or double quotes.
A "." preceding a directive (for example, if, and set) is always expected to start a new line.
An end of line is always expected after {.
A CLI command is always expected to start a new line.
Passed-in (dynamic) variables are always read-only inside an EHS script and cannot be overwritten using a set statement.
.if commands support == and != operators only.
.if and .set commands support addition, subtraction, multiplication, and division of integers.
.if and .set commands support concatenation of strings.
Valid examples:
configure service epipe $serviceID
where $serviceID is either a local integer variable or passed-in integer variable
echo srcAddr is $srcAddr
where $srcAddr is a passed-in string variable
.set $ipAddr = "10.0.0.1"
where $ipAddr is a local string variable
.set $ipAddr = $srcAddr
where $srcAddr is a passed-in string variable
$ipAddr is a local string variable
.set ($customerID = 50)
where $customerID is a local integer variable
.set ($totalPackets = $numIngrPackets + $numEgrPackets)
where $totalPackets, $numIngrPackets, $numEgrPackets are local integer variables
.set ($portDescription = $portName + $portLocation)
where $portDescription, $portName, $portLocation are local string variables
if ($srcAddr == "CONSOLE") {
CLI_commands_set1
.else {
CLI_commands_set2
.} endif
where $srcAddr is a passed-in string variable
CLI_commands_set1 is a set of one or more CLI commands
CLI_commands_set2 is a set of one or more CLI commands
.if ($customerId == 10) {
CLI_commands_set1
.else {
CLI_commands_set2
.} endif
where $customerID is a passed-in integer variable
CLI_commands_set1 is a set of one or more CLI commands
CLI_commands_set2 is a set of one or more CLI commands
.if ($numIngrPackets == $numEgrPackets) {
CLI_commands_set1
.else {
CLI_commands_set2
.} endif
where $numIngrPackets and $numEgrPackets are local integer variables
CLI_commands_set1 is a set of one or more CLI commands
CLI_commands_set2 is a set of one or more CLI commands
Invalid examples:
.set $srcAddr = "10.0.0.1"
where $srcAddr is a passed-in string variable
Reason: passed-in variables are read-only in an EHS script
.set ($ipAddr = ‛$numIngrPackets' + $numEgrPackets)
where $ipAddr is a local string variable
$numIngrPackets and $numEgrPackets are local integer variables
Reason: variable types do not match; cannot assign a string to an integer
.set ($numIngrPackets = $ipAddr + $numEgrPackets)
where $ipAddr is a local string variable
$numIngrPackets and $numEgrPackets are local integer variables
Reason: variable types do not match; cannot concatenate a string to an integer
.set $ipAddr = "10.0.0.1"100
where $ipAddr is a local string variable
Reason: when double quotes are used, they must enclose the entire string
.if ($totalPackets == "10.1.1.1") {
.} endif
where $totalPackets is a local integer variable
Reason: cannot compare an integer variable to a string value
.if ($ipAddr == 10) {
.} endif
where $ipAddr is a local string variable
Reason: cannot compare a string variable to an integer value
.if ($totalPackets == $ipAddr) {
where $totalPackets is a local integer variable
$ipAddr is a local string variable
Reason: cannot compare an integer variable to a string variable