Script bug on find command by variable?

I was writing a script and I guess found a bug.
When I use find command with variable, it returns all results without filtering.

# CODE
/interface {
  :local name "ether1"
  :put [find name=$name]
  :put [find name="ether1"]
  :put ($name = "ether1")
}

# RESULT
*1;*2;*3;*4;*5;*6
*1
true

This code was executed just after when I reset the device using reset button.
I will attach detailed device information.

/system/routerboard/print

routerboard: yes
        board-name: hEX
             model: RB750Gr3
          revision: r4
     serial-number: 
     firmware-type: mt7621L
  factory-firmware: 6.47.10
  current-firmware: 7.8
  upgrade-firmware: 7.10

Reserved_variable_names
probably some variable like name already reserved by ros itself.
it does happen on ros v6 as well, tested on v6.49.7.

{:local iName "ether1"; :put [/interface find name=$iName}

find name=$name
“find where name is identical to own name”

and obviously all interface have the name = to the interface $name itself…
*1;*2;*3;*4;*5;*6


A-B-C of programming: never use parameters names as variable names…


And the topic title, AS USUAL, since you don’t understand these things, it probably MUST be a bug on RouterOS, because it is impossible for you to be wrong.
Example of correct title: How works “find name=$name”?

:put [find name=$name]

This is comparing name property with its own value for each interface list iteration, since properties are mapped into variables with same name. In this case every condition matches and that’s why returns list of all interfaces. To see that execute:

/interface/find name=[:put $name]

and you will see that it will print name of each interface you have, doesn’t matter if name variable is previously set or not.

Not sure “reserved keywords” is the best explanation… I think of the CLI cmd’s properties as “inherited variables”, based what can be used in a set/get/find – so the list of them varies depending on the current CLI path/context. And these inherited variables are a “const” (read-only) local variable so they can’t be reassigned.

Exactly, correct term is reserved variable names not keywords (per command), as stated here https://wiki.mikrotik.com/wiki/Manual:Scripting#Reserved_variable_names. Variable with name as some of property names for command should not be used for that command, this is just for command scope, that variable still can be used out of command scope.

Probably correct term is parameter (or field, or property), not variable and not reseved keyword…

Parameter is part of command, you don't have ability to define/change them in code, it is part of syntax, while variable names you can. Field or property are defined named parts of data for certain entity (config. record). When you defining how something needs to be named it is about something that you can control in source which are in this case variable names. :slight_smile:

Thank you for everyone!
And I’m sorry for not appropriate title…
I’ll check more carefully my mistake if something was went wrong.