Setup guide

Variables
Description
Console allows you to create and use global (system wide) and local (only usable within the current
script) variables. Variables can be accessed by writing '$' followed by a name of variable. Variable
names can contain letters, digits and '-' character. A variable must be declared prior to using it in
scripts. There are three types of declaration available:
global - defined by action global, global variables can be accessed by all scripts and console
logins on the same router. Variables are not kept across reboots.
local - defined by action local, local variables are not shared with any other script, other
instance of the same script or other console logins. Its value is lost when script finishes.
loop index variables - defined within for and foreach statements, these variables are used only
in do block of commands and are removed after command completes.
monitor action - some monitor commands that have do part can also introduce variables.
You can assign a new value to a variable using set action. It has two arguments: the name of the
variable and the new value of the variable. After variable is no longer needed, it's name can be freed
by :unset command. If you free local variable, it's value is lost. If you free global variable, it's value
is still kept in router, it just becomes inaccessible from current script.
Notes
Loop variables "shadows" already introduced local variables with the same name.
Example
[admin@Wandy] ip route> /
[admin@Wandy] > :global g1
[admin@Wandy] > :set g1 "this is global variable"
[admin@Wandy] > :put $g1
this is global variable
[admin@Wandy] >
Command Substitution and Return Values
Description
Some console commands are most useful if their output can be used as an argument value in other
commands. In console, this is done by "returning" value from commands. Return value is not
displayed on the screen. When you type such a command between square brackets '[' ']', this
command is executed and it's return value is used as the value of these brackets. This is called
command substitution.
The commands that return usefull values are, but not limited to: find, /ping - returns the number of
sucessful pings, time - returns the measured time value, incr and decr return the new value of a
variable, add - return the internal number of newly created item.
Example
Consider the usage of find command: