Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Comments

The following rules apply to a comment:

  • A comment starts with a hash character (#) and ends at the end of the physical line.

...

  • RouterOS does not support multiline comments.
  • If (#) character appears inside the string it is not considered a comment.
Example
Code Block
languageros
# this is a comment 
# next badline comment 
:global a; # badanother valid comment 

:global myStr "lalapart of the string # this is not a comment"

Line joining

Two or more physical lines may be joined into logical lines using the backslash character (\).

The following rules apply to use backslash as a line joining tool:

  • 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.
Example
Code Block
languageros
:if ($a = true \
	and $b=false) do={ :put “$a $b”; } 
:if ($a = true \ # bad comment 
	and $b=false) do={ :put “$a $b”; }
# comment \
	continued – invalid (syntax error)

...

Variables can be used only in certain regions of the script called scopes. These regions are called scopes. Scope determines determine the visibility of the variable. There are two types of scopes - global and local. A variable declared within a block is accessible only within that block and blocks enclosed by it, and only after the point of declaration.

Global scope

Global scope or root scope is the default scope of the script. It is created automatically and can not be turned off.

Local scope

User can define their own groups to block access to certain variables, these scopes are called local scopes. Each local scope is enclosed in curly braces ("{ }").

...

In the code above variable, b has local scope and will not be accessible after a closing curly brace.

Note

...

Each line written in the terminal is treated as local scope

So for example, the defined local variable will not be visible in the next command line and will generate a syntax error

[admin@MikroTik] > :local myVar a;
[admin@MikroTik] > :put $myVar
syntax error (line 1 column 7)


Warning

...

Do not define global variables inside local scopes.


Note that even variable can be defined as global, it will be available only from its scope unless it is not already defined.

...

The code above will generate an errorexpected result because the accessibility of variable "b" and its value will end after the end of the scope.

Keywords

The following words are keywords and cannot be used as variable and function names:

...

Following escape sequences can be used to define certain special character characters within a string:

\"Insert double quote
\\Insert backslash
\nInsert newline
\rInsert carriage return
\tInsert horizontal tab
\$Output $ character. Otherwise, $ is used to link the variable.
\?Output ? character. Otherwise ? is used to print "help" in the console. Removed since v7.1rc2
\_- space
\a- BEL (0x07)
\b- backspace (0x08)
\f- form feed (0xFF)
\vInsert vertical tab
\xxA print character from hex value. Hex numbers should use capital letters.

...

Note: for the division to work you have to use braces or spaces around the dividend so it is not mistaken as an IP address

Relational Operators

...

Note: Starting from v6.2 there can be undefined variables. When a variable is an undefined, the parser will try to look for variables set, for example, by DHCP lease-script or Hotspot on-login

...