Community discussions

MikroTik App
 
Freman
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 76
Joined: Thu Jul 01, 2004 8:49 am

Scripting.. missing :unset command

Thu Mar 16, 2006 5:09 am

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)
 
eflanery
Member
Member
Posts: 376
Joined: Fri May 28, 2004 10:11 pm
Location: Moscow, ID
Contact:

Thu Mar 16, 2006 9:33 pm

: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
 
User avatar
LatinSuD
Member Candidate
Member Candidate
Posts: 181
Joined: Wed Jun 29, 2005 1:05 pm
Location: Spain
Contact:

Re: Scripting.. missing :unset command

Wed Sep 05, 2007 2:44 pm

Manual should be updated then! :o

http://www.mikrotik.com/testdocs/ros/2. ... ipting.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".
 
sten
Forum Veteran
Forum Veteran
Posts: 919
Joined: Tue Jun 01, 2004 12:10 pm

Re: Scripting.. missing :unset command

Tue Dec 25, 2007 6:22 am

Manual should be updated then! :o

http://www.mikrotik.com/testdocs/ros/2. ... ipting.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
 
alli
newbie
Posts: 37
Joined: Tue Jan 24, 2017 5:43 pm

Re: Scripting.. missing :unset command

Wed Jun 13, 2018 4:14 am

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.

Who is online

Users browsing this forum: No registered users and 70 guests