Why is that?
How can I work around it?
Shouldn’t this script be a function that returns the day of the week so it can be used in a more general fashion?
The console doesn’t maintain its own variables. As soon as you call :local, the next line doesn’t have it. That’s why “set” fails - there’s no variable to be changed. The previous lines that reference the variable don’t fail - they resolve the variable to a value of type “nothing”.
You can workaround this by wrapping the whole script with “{” and “}”. Alternatively, have it in “/system script”, and then run it with “/system script run”.
AFAIK, yes, though you could also write multiple commands on the same line, separated with “;”. On the console, everything on one line is part of the same local block, so
:local var "val";:put $var
will output “val”, as expected.
As a reference http://wiki.mikrotik.com/wiki/Manual:Scripting . Doesn’t quite have an EBNF, but it does have a general command syntax near the top that almost all commands follow. Reading the whole page, you can infer the whole language’s grammar (if you were to go as far as creating a custom parser or something…).
Though “:set” is actually an outlier. You don’t have to use
:set "var" "new value"
to change $var. You can instead have
:set $var "new value"
though that doesn’t quite make sense IMHO, and you can set associative array keys with
:set ($var->"key") "new value"
which also doesn’t quite make sense with how every other command is used.