Community discussions

MikroTik App
 
dhiaahmed
just joined
Topic Author
Posts: 10
Joined: Sat Mar 31, 2018 1:05 pm

Checking the empty value

Fri Nov 20, 2020 11:39 am

I don't know a lot about scripting in mikrotik and I really need to know how to check the empty value.
For example: when I write it like this it doesn't work I don't know why!!
global z ; 
if ($z="") do={put "hello world"}
 
User avatar
eworm
Forum Veteran
Forum Veteran
Posts: 719
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Checking the empty value

Sun Nov 22, 2020 5:58 pm

Because your variable is nothing, but you check for an empty string. That's something different. Try this:
:global z; 
:if ($z=[]) do={:put "hello world";}
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
msatter
Forum Guru
Forum Guru
Posts: 1968
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Checking the empty value

Sun Nov 22, 2020 7:06 pm

Some other ways to check:

([:len $z]=0) works also for array
([:typeof $z] ~ "(nil|nothing)")
I did not knew the =[ ] and that one could replace the :len one for me.
One RB4011 (cooled) and a RB760iGS (hEX S) in series. The 4011 Does PPPoE/IKEv2.
The cooler: viewtopic.php?f=3&t=138613&start=300#p799879
Running:
RouterOS 6.48beta58 / Winbox 3.27 64bits / MikroTik APP 1.3.15
 
dhiaahmed
just joined
Topic Author
Posts: 10
Joined: Sat Mar 31, 2018 1:05 pm

Re: Checking the empty value

Fri Nov 27, 2020 11:23 am

I've tried this but it didn't work :(
:global z; 
:if ($z=[]) do={:put "hello world";} 

Who is online

Users browsing this forum: ilium007 and 26 guests