Foreach syntax

Hi, could you help me with this?
It may be silly but I don’t know what I’m missing…

I want to change the “interface list” of a number of interfaces that contain the word “ospf” and replace ListA with the new ListB.

[ ] > interface/list/member pr
Columns: LIST, INTERFACE
# LIST      INTERFACE
0 ListA     wg-ospf-to-A
1 ListA     wg-ospf-to-B
2 ListA     wg-ospf-to-C
3 ListA     wg-ospf-to-D

{
/interface list
add name=ListB

:delay 1s

/interface
:foreach i in=[find name~"ospf"] do={
    list/member set $i list=ListB
}
}

Output: 
no such item (4)

In Winbox it is easy to change it, but I want to learn how to do it by CLI.

Thanks in advance.

Sorry, but after several tests I have already discovered the solution.


{
/interface list
add name=ListB

:delay 1s

/interface/list/member
:foreach i in=[find where ((interface~"ospf") and (list~"ListA"))] do={
    set $i list="ListB"
}
}

No apologizes needed for solving your own problem :slight_smile:

One tip to help spotting the inheiret command path is using spaces & curly braces after the path and put your code there. Just style, but helps keep track visually what the [find] refers.


/interface/list {
   add name=ListB
   :delay 1s
}

/interface/list/member {
  :foreach i in=[find where ((interface~"ospf") and (list~"ListA"))] do={
      set $i list="ListB"
  }
}

Both work, just an idea. But you might have spotted the /interface vs /interface/list/member sooner :wink:

OK, thanks for the tip @Amm0.

BR.

I do not like that way.
Better this:

/interface list
add name=ListB
member set [find where list="ListA" and interface~"ospf"] list="ListB"

Good, thanks!