Command line can be constructed from more than one physical line by following line joining rules.

Physical Line

A physical line is a sequence of characters terminated by an end-of-line (EOL) sequence. Any of the standard platform line termination sequences can be used:

unix – ASCII LF;

windows – ASCII CR LF;

mac – ASCII CR;

Standard C conventions for new line characters can be used ( the \n character).

Comments

A comment starts with a hash character (#) and ends at the end of the physical line. Whitespace or any other symbols are not allowed before hash symbol. Comments are ignored by syntax. If (#) character appear inside string it is not considered a comment.

Example

# this is a comment
# bad comment
:global a; # bad comment
:global myStr "lala # this is not a comment"

Line joining

Two or more physical lines may be joined into logical lines using backslash character (\). A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does not continue a token except for string literals. A backslash is illegal elsewhere on a line outside a string literal.

Bitwise Operators

bitwise OR. Performs logical OR operation on each pair of corresponding bits. In each pair the result is “1” if one of bits or both bits are “1”, otherwise the result is “0”.

“^”

bitwise XOR. The same as OR, but the result in each position is “1” if two bits are not equal, and “0” if bits are equal.

“&”

bitwise AND. In each pair the result is “1” if first and second bit is “1”. Otherwise the result is “0”.

“<<”

left shift by given amount of bits

“>>”

right shift by given amount of bits

Concatenation Operators

Opearator

Description

Example

“.”

concatenates two strings

:put (“concatenate” . “ “ . “string”);

“,”

concatenates two arrays or adds element to array

:put ({1;2;3} , 5 );

Other Operators

Opearator

Description

Example

“[]”

command substitution

:put [ :len "my test string"; ];

“()”

sub expression operator

:put ( "value is " . (4+5));

“->”

access operator

(object)->(key)

“$”

substitution operator

:global a 5; :put $a;

Variables

Scripting language has two types of variables:

global - accessible from all current users scripts, defined by global keyword;

local - accessible only within the current scope, defined by local keyword.

Every variable, except for built in RouterOS variables, must be declared before usage by local or global keywords. Undefined variables will be marked as undefined and will result in compilation error.
Example:

# following code will result in compilation error, because myVar is used without declaration
:set myVar "my value";
:put $myVar

Correct code:

:local myVar;
:set myVar "my value";
:put $myVar;

Valid characters in variable names are letters and digits. If variable name contains any other character, then variable name should be put in double quotes. Example:

If variable is initially defined without value then variable data type is set to nil, otherwise data type is determined automatically by scripting engine. Sometimes conversion from one data type to another is required. It can be achieved using data conversion commands. Example:

It terminates the nearest enclosing loop. If a for loop is terminated by break, the loop control target keeps its current value. break may only occur syntactically nested in a for or while loop.

continue

:continue

It continues with the next cycle of the nearest enclosing loop. continue may only occur syntactically nested in a for or while loop.

Menu specific commands

Common commands

Following commands available from most sub-menus:

Command

Syntax

Description

add

add <param>=<value>..<param>=<value>

add new item

remove

remove <id>

remove selected item

enable

enable <id>

enable selected item

disable

disable <id>

disable selected item

set

set <id> <param>=<value>..<param>=<value>

change selected items parameter, more than one parameter can be specified at the time

get

get <id> <param>=<value>

get selected items parameter value

print

print <param><param>=[<value>]

print menu items. Output depends on print parameters specified. Most common print parameters are described here

export

export [file=<value>]

export configuration from current menu and its sub-menus (if present). If file parameter is specified output will be written to file with extension '.rsc', otherwise output will be printed to console. Exported commands can be imported by import command