[BUG] Parameters having a string value ending in \$ need to be initialised with parenthesis but variables don't.

It looks like when you initialise a parameter having a string value ending in $ you not only need to escape it, but also surround it with parenthesis but that is not needed for local variables.

Why is that?

If you forget the parenthesis, then you see it fail.
It doesn’t give me a comfortable feel about the scripting language.

Just try running the below code on the console (examples from https://gist.github.com/jpluimers/9b239814e3b0aa5a3d0853efc02d9861 )

{
  :local showValue do={
    :local logLine "value='$value'"
    :put $logLine
  }

  ## fails each line that ends after \$" with a `syntax error (line 12 column 4)` (the line numbers vary)

  :put "-----------------------------start"
  $showValue value="^scripts.Function..*"
  $showValue value="^scripts.Function..*\$"
  $showValue value=("^scripts.Function..*\$")
  $showValue value="\$"
  $showValue value=("\$")
  :put "-----------------------------finish"
}

This one works though:

# showValuesFromParameters
{
  :local showValue do={
    :local logLine "value='$value'"
    :put $logLine
  }

  :put "-----------------------------start"
  $showValue value="^scripts.Function..*"
  $showValue value=("^scripts.Function..*\$")
  $showValue value=("\$")
  :put "-----------------------------finish"
}

And it will give you this output:

-----------------------------start
value='^scripts.Function..*'
value='^scripts.Function..*$'
value='$'
-----------------------------finish

The odd thing is that it works fine for :local variables, whether they are directly initialised at declaration time or later using a :set statement:

{
  :local showValuesFromDirectInitilisation do={
    :local value1 "^scripts.Function..*"
    :local logLine1 "value='$value1'"
    :put $logLine1

    :local value2 "^scripts.Function..*\$"
    :local logLine2 "value='$value2'"
    :put $logLine2

    :local value3 ("^scripts.Function..*\$")
    :local logLine3 "value='$value3'"
    :put $logLine3

    :local value4 "\$"
    :local logLine4 "value='$value4'"
    :put $logLine4

    :local value5 ("\$")
    :local logLine5 "value='$value5'"
    :put $logLine5
  }
  :put "-----------------------------start"
  $showValuesFromDirectInitilisation
  :put "-----------------------------finish"
}

and

{
  :local showValuesFromSetInitilisation do={
    :local value
    :local logLine

    :set $value "^scripts.Function..*"
    :set logLine "value='$value'"
    :put $logLine

    :set $value "^scripts.Function..*\$"
    :set logLine "value='$value'"
    :put $logLine

    :set $value ("^scripts.Function..*\$")
    :set logLine "value='$value'"
    :put $logLine

    :set $value "\$"
    :set logLine "value='$value'"
    :put $logLine

    :set $value ("\$")
    :set logLine "value='$value'"
    :put $logLine
  }
  :put "-----------------------------start"
  $showValuesFromSetInitilisation
  :put "-----------------------------finish"
}

both give this result:

-----------------------------start
value='^scripts.Function..*'
value='^scripts.Function..*$'
value='^scripts.Function..*$'
value='$'
value='$'
-----------------------------finish

So again: why the difference for parameters?

And what about assignment patterns: should you always initialise parameters and variables using parenthesis around them?

–jeroen

I’d call that a bug, but as far as

You don’t always “have to”, but you may, and it is the universally safer option, so yeah. If in doubt, do use parenthesis.

Works fine if you add ; at the end of line.

{
  :local showValue do={
    :local logLine "value='$value'";
    :put $logLine
  }
  :put "-----------------------------start";
  $showValue value="^scripts.Function..*";
  $showValue value="^scripts.Function..*\$";
  $showValue value=("^scripts.Function..*\$");
  $showValue value="\$";
  $showValue value=("\$");
  :put "-----------------------------finish"
}

So it’s still a bug that needs to be solved: the ‘end-of-commandline’ isn’t always correctly adhered to. http://wiki.mikrotik.com/wiki/Manual:Scripting#Command_line

But now I at least understand why some people put semicolons at the end of every line.

I never understood in the first place why you’d have both semicolon and various newline terminate commands (and even have exceptions when you don’t need those).

A clear language specification should make that a lot easier to cope with.

–jeroen