Setup guide
\... do={:put $i; :incr i;}; :unset i;}
0
1
2
3
4
5
6
7
8
9
[admin@Wandy] >
do - this action takes one argument, which holds the console commands that must be executed. It is
similar to the do statement of other commands. It has also two parameters, while and if. If no
parameters are given, do just executes its payload once, which does not make much use. However if
you specify a condition as a value for the while argument, it will be evaluated after executing
commands, and if it will return true, do statement is executed again and again until false. If you
specify a condition for the if argument, it is evaluated only once before doing anything else, and if it
is false, nothing is done.
[admin@Wandy] > {:global i; :set i 10; :do{:put $i; :decr i;} \
\... while (($i < 10) && ($i > 0)); :unset i;}
10
9
8
7
6
5
4
3
2
1
[admin@Wandy] >
for - this action takes one argument, the name of the loop variable. It has also four parameters,
from, to, step and do. First two parameters indicate the borders for the loop counter. The interval
includes these two values as well. The third one specifies the step of decrement (or increment).
And, finally, the do statement holds console commands to repeat.
[admin@Wandy] > :for i from=1 to=100 step=37 do={:put ($i . " - " . 1000/$i)}
1 - 1000
38 - 26
75 - 13
[admin@Wandy] >
foreach - this action takes one argument, the name of the loop variable. It has also two parameters,
in and do. The in argument is treated as a list with each value assigned to the loop variable, and do
statement executed for this value. If in value is not a list then do statement is executed only once. in
case in value is empty, do statement is not executed at all. This way it is optimized to work with
find command, which returns lists of internal numbers, and may return an empty list or just one
internal number. This example prints all ethernet interfaces, each followed by all addresses that are
assigned to it:
[admin@Wandy] > :foreach i in=[/interface find type=ether ] do={
{... :put [/interface get $i name]
{... :foreach j in=[/ip address find interface=$i] do={
{{... :put [/ip address get $j address]
{{... }
{... }
ether1
ether2
10.0.0.65/24