System information
Manual:Scripting
23
Line structure
RouterOS script is divided into number of command lines. Command lines are executed one by one until the end of
script or until runtime error occur.
Command line
RouterOS console uses following command syntax:
[prefix] [path] command [uparam] [param=[value]] .. [param=[value]]
•• [prefix] - ":" or "/" character which indicates if command is ICE or path. May or may not be required.
•• [path] - relative path to the desired menu level. May or may not be required.
•• command - one of the commands available at the specified menu level.
•• [uparam] - unnamed parameter, must be specified if command requires it.
•• [params] - sequence of named parameters followed by respective values
The end of command line is represented by the token “;” or NEWLINE. Sometimes “;” or NEWLINE is not required to
end the command line.
Single command inside (), [] or {} does not require any end of command character. End of command is
determined by content of whole script
:if ( true ) do={ :put "lala" }
Each command line inside another command line starts and ends with square brackets "[ ]" (command
concatenation).
:put [/ip route get [find gateway=1.1.1.1]];
Notice that code above contains three command lines:
•• :put
•• /ip route get
•• find gateway=1.1.1.1
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.
# this is a comment
# bad comment
:global a; # bad comment
:global myStr "lala # this is not a comment"