Script does not work at startup from /system script

Why if you run this script


:global a true
:global b true

:if ($a = true) do={:global InterfaceName "ether1"}

:if ($b = true) do={:global MacAddress [/interface ethernet get [find where name=$InterfaceName] mac-address]}

using command


/system script run <script id>

it does not work, and if you run this script


:global a true
:global b true

:if ($a = true) do={:global InterfaceName "ether1"}

:global InterfaceName $InterfaceName

:if ($b = true) do={:global MacAddress [/interface ethernet get [find where name=$InterfaceName] mac-address]}

using the same command


/system script run <script id>

does it work?

And if you run this script using copying and pasting into the terminal, both options work

This is bug?

It’s expected. Try reading about the “scopes” in the scripting manual - there is identical example.
https://wiki.mikrotik.com/wiki/Manual:Scripting#Local_scope

Note that even variable can be defined as global, it will be available only from its scope unless it is not already defined.

Thanks! I understand! I did not think that in relation to the global this applies..