Script - do not remove

Hello,

how can I NOT remove the default route here if WAN1 is found?

if ([/interface get WAN1]) do={/ip route remove [/ip route find dst-address=0.0.0.0/0]}
if (![/interface get WAN1]) do={/ip route remove [/ip route find dst-address=0.0.0.0/0]}

It is the “!”

Or

if ([/interface get WAN1]) do={} else={/ip route remove [/ip route find dst-address=0.0.0.0/0]}

thank you very much, it works perfectly

this:
[/interface get WAN1]
causes an error if WAN1 is NOT found and the script is aborted
and from that we can’t get the true or false value, but all the properties of the interface
For example try

:put [/interface get WAN1]

How do correctly do that (ignoring why you delete the route):

# if 0 interface named WAN1 is found, delete (all) routes that have 0.0.0.0/0 as destination address
:if ([:len [/interface find where name="WAN1"]] = 0) do={ /ip route remove [find where dst-address=0.0.0.0/0] }

# if (exactly) 1 interface named WAN1 is found, delete (all) routes that have 0.0.0.0/0 as destination address
:if ([:len [/interface find where name="WAN1"]] = 1) do={ /ip route remove [find where dst-address=0.0.0.0/0] }