Scripting.. missing :unset command

I just tried to unset a global variable left over from a script to disconnect users…

Well.. it doesn’t work…

[admin@Springbrook] > :unset g1
no such command or directory (unset)

Anyone else missing an :unset?

This is 2.9.5 and 2.9.17 it’s missing in (I don’t know about other versions)

:unset only works in 2.8. In 2.9, just use :set without a new value:

:global foo 17
:env pr

Global Variables
foo=17
Local Variables

:set foo
:env pr

Global Variables
Local Variables

–Eric

Manual should be updated then! :astonished:

http://www.mikrotik.com/testdocs/ros/2.9/system/scripting.php

Btw, because of wrong documentation i got into this error:

:local myvar
:foreach i in=1 do={ :set myvar hello }
:put ( [:typeof $myvar] . $myvar )

nil

What i thought i was doing:

  • Declare a local variable $myvar.
  • Update value of myvar to “hello”

What i was actually doing:

  • Unsetting (deleting) the variable $myvar.
  • Creating a variable $myvar. Because it did not exist when entering the loop, it is defined as local to the loop!
  • There is no $myvar when i do the :put, that’s why it is “nil”.

That is because you did not define myvar with a value first. :local and :global can be used to remove local only or global only variables.
Try this instead:

:local myvar ""
:foreach i in=1 do={ :set myvar hello }
:put ( [:typeof $myvar] . $myvar )

nil

Calling :set on variable without any value seems to work like unset (v6.42.3), check this:

:global a 1
/environment print
:set $a 
/environment print

it works even on array’s elements.