work in console not in script

Hello,

I’m a bit confused …

When I launch this command on console It Works and retun all the entries expected :

[/interface/wireguard/peers];
:foreach Id in=[find disabled=no] do={
:put [get $Id comment];
:put [get $Id last-handshake];

} But when this lines are put in a script file, I Have an error when running the script.

expected end of command (line 7 column 30) corresponding to the = sign in the line :foreach Id in=[find disabled=no] do={


Best regards.

Felix

If you don’t write correctly, it’s obvious that it doesn’t work, or that it works randomly.

Where did you read this and what does this represent?
[/interface/wireguard/peers];

@felix34, remove the brackets from the first line ie:
/interface/wireguard/peers
:foreach Id in=[find disabled=no] do={
:put [get $Id comment]
:put [get $Id last-handshake]
}

or:

:foreach Id in [/interface/wireguard/peers find disabled=no] do={
:put [get $Id comment]
:put [get $Id last-handshake]
}