Difference between revisions of "Manual:Scripting"

From MikroTik Wiki
Jump to navigation Jump to search
(New page: <div class=manual> <h2>Scripting language manual</h2> lala <h3>Line structure</h3> <p>RouterOS script is divided into number of logical lines.</p> <h4>Logical line</h4> <p>The end of log...)
Line 108: Line 108:
:put "This\nis\na\ntest";
:put "This\nis\na\ntest";
which will show on display<br>
which will show on display
( MRZ: bugs vai fiicha ??? ka whitespaci katras jaunas rindas priekshaa??? ).
( MRZ: bugs vai fiicha ??? ka whitespaci katras jaunas rindas priekshaa??? ).



Revision as of 06:19, 26 September 2008

Scripting language manual


Line structure

RouterOS script is divided into number of logical lines.

Logical line

The end of logical line is represented by the token “;” or NEWLINE. Logical 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).


A comment starts with a hash character (#) and ends at the end of the physical line. A comment signifies the end of the logical line unless line joining rules are invoked ( nav taisniiba, skat piemeerus). Comments are ignored by syntax. If (#) character appear inside string it is not considered a comment.

# this is a comment

:global a; # bad comment (MRZ: shitadu vajadzetu atlaut)

: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. (MRZ: nezinu vai shii ir taisniiba, buutu logiski ja taa buutu). A backslash is illegal elsewhere on a line outside a string literal.

: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)

Whitespace between tokens

Whitespace can be used to separate tokens. Whitespace is necessary between two tokens only if their concatenation could be interpreted as a different token.

   :local a true; :local b false;
   :put (a&&b);      # whitespace is not required
   :put (a and b);   # whitespace is required


( Vai RouterOSaa vispaar ir keywordi??? )
The following words are keywords and cannot be used as variable and function names:

and       or        not       break
continue  do        for       foreach
in        from      to        while
global    local     if        else

(break un continue vajadzeetu ieviest)
(varbuut veel kaads?)


The following tokens serve as delimiters in the grammar:

()  []  {}  :   ;   $   / 

Data types

RouterOS scripting language has following data types:

  • number - 64bit signed integer, possible hexadecimal input;
  • boolean - values can bee true or false;
  • string - character sequence (??? kaads ir memas limits ???);
  • IP - IP address;
  • internal ID - hexadecimal value prefixed by '*' sign. Each menu item has assigned unique number - internal ID;
  • time - date and time value;
  • array - sequence of values organized in an array.

Constant Escape Sequences

Following escape sequences can be used to define certain special character within string: \' - single quote \" - double quote \\ - backslash \n - newline \r - carriage return \t - horizontal tab \$ (MRZ: varbuut veel kaads)


:put "This\nis\na\ntest";

which will show on display This


( MRZ: bugs vai fiicha ??? ka whitespaci katras jaunas rindas priekshaa??? ).