Community discussions

MikroTik App
 
MyThoughts
Member Candidate
Member Candidate
Topic Author
Posts: 218
Joined: Sat Sep 17, 2005 9:07 pm

How do you clear a global variable?

Tue Dec 09, 2008 11:39 pm

I'm stuck updating some old v2.9.x scripts to work with v3.17 but I can't find a way to clear a defined global variable.

Can anyone post the command(s) necessary to clear an already defined global variable?

I've reviewed the only available documentation (http://wiki.mikrotik.com/wiki/Scripting) but it doesn't even mention clearing global variables.

Cheers
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7199
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: How do you clear a global variable?

Wed Dec 10, 2008 8:35 am

By clearing you man delete it? It is not possible, only thing you can do is to set it to nil.
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: How do you clear a global variable?

Wed Dec 10, 2008 10:07 am

Greetings!
The variables are in
/system script environment
Do a print and then use
remove X
where X is the line number of the variable you want to delete.
 
MyThoughts
Member Candidate
Member Candidate
Topic Author
Posts: 218
Joined: Sat Sep 17, 2005 9:07 pm

Re: How do you clear a global variable?

Thu Dec 11, 2008 9:11 pm

Thanks for the replies the '/system script enviroment' method works great. I was really getting tired of unneeded global variables.

Cheers
 
Ehman
Member
Member
Posts: 391
Joined: Mon Nov 15, 2010 10:49 pm

Re: How do you clear a global variable?

Sat Oct 26, 2013 5:47 pm

Thanks for the replies the '/system script enviroment' method works great. I was really getting tired of unneeded global variables.

Cheers
Still impossible ?

I use the NO-IP mikrotik scrip, and every now and then, I run this command "/system script environment remove [find user="admin"]" to remove everything, so that I can do a forced IP update

but of course now after a upgrade , the old scripts doesn't work!!! :(
 
SurferTim
Forum Guru
Forum Guru
Posts: 4636
Joined: Mon Jan 07, 2008 10:31 pm
Location: Miramar Beach, Florida

Re: How do you clear a global variable?

Sat Oct 26, 2013 8:24 pm

I use the NO-IP mikrotik scrip, and every now and then, I run this command "/system script environment remove [find user="admin"]" to remove everything, so that I can do a forced IP update

but of course now after a upgrade , the old scripts doesn't work!!!

There is no "user" field in "/system script environment". That is probably why it is not running.
 
Ehman
Member
Member
Posts: 391
Joined: Mon Nov 15, 2010 10:49 pm

Re: How do you clear a global variable?

Sun Oct 27, 2013 3:13 am

I use the NO-IP mikrotik scrip, and every now and then, I run this command "/system script environment remove [find user="admin"]" to remove everything, so that I can do a forced IP update

but of course now after a upgrade , the old scripts doesn't work!!!

There is no "user" field in "/system script environment". That is probably why it is not running.


exactly... older versions of ros always said user=admin ... new version...nope

I've changed all the :global to :local ..no more issue's
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7199
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: How do you clear a global variable?

Mon Oct 28, 2013 9:37 am

Starting with v6.2 you can unset global variables:
[admin@pe0] /system> :global aa 1
[admin@pe0] /system> :environment print 
aa=1

[admin@pe0] /system> :set aa 
[admin@pe0] /system> :environment print 

[admin@pe0] /system> 
 
EtienneO
just joined
Posts: 7
Joined: Wed Apr 11, 2012 6:44 pm

Re: How do you clear a global variable?

Wed May 18, 2016 11:06 am

Script to clear all variables

:if ([:len [/system script environment find]] != 0) do={
:for E from=0 to=([:len [/system script environment find]] - 1) do={
/system script environment remove $E
}}
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

Re: How do you clear a global variable?

Wed May 18, 2016 12:10 pm

Script to clear all variables

:if ([:len [/system script environment find]] != 0) do={
:for E from=0 to=([:len [/system script environment find]] - 1) do={
/system script environment remove $E
}}
Could just use:
/system script environment remove [find]
The command doesn't complain if nothing is found.
And you can easily make it only delete a variable with a specific name if need be.
/system script environment remove [find name="ThatVar"]
When using WinBox you can also go to "System -> Scripts -> Environment tab" where you have a full list of all global variables and can delete any you you want. You can even change the value of a global variable in this menu.

Remember that you need FULL ADMIN permissions to do either of these.
 
EtienneO
just joined
Posts: 7
Joined: Wed Apr 11, 2012 6:44 pm

Re: How do you clear a global variable?

Wed May 18, 2016 4:33 pm

Script to clear all variables

:if ([:len [/system script environment find]] != 0) do={
:for E from=0 to=([:len [/system script environment find]] - 1) do={
/system script environment remove $E
}}
Could just use:
/system script environment remove [find]
The command doesn't complain if nothing is found.
And you can easily make it only delete a variable with a specific name if need be.
/system script environment remove [find name="ThatVar"]
When using WinBox you can also go to "System -> Scripts -> Environment tab" where you have a full list of all global variables and can delete any you you want. You can even change the value of a global variable in this menu.

Remember that you need FULL ADMIN permissions to do either of these.
Thanks, I was not aware that you can simply add a [find] at the end of the command to remove.
 
User avatar
Deantwo
Member
Member
Posts: 332
Joined: Tue Sep 30, 2014 4:07 pm

Re: How do you clear a global variable?

Wed May 18, 2016 4:56 pm

Thanks, I was not aware that you can simply add a [find] at the end of the command to remove.
The "[find]" simply selects all objects that matches the search criteria and added them to an array.
If there is more than one object the "remove" command is simply repeated for each object in the array. Same way as if you had done a ":foreach" loop.