Community discussions

MikroTik App
 
dfdf
newbie
Topic Author
Posts: 36
Joined: Wed Dec 08, 2021 3:51 pm

One more strange issue (nothing is NOT nothing?)

Sat May 06, 2023 8:38 am

Tested on ROS 7.8:

trying to filter out script jobs with
/system/script/job/print where script!="" 
gives unexpected results...

Expected (ok):
[admin@df.router] > :foreach "i" in=([/system script job print as-value detail]) do={ :put [:typeof ($"i"->"script")] }
nothing
nothing

Expected (ok):
[admin@df.router] > :foreach "i" in=([/system script job print as-value detail]) do={ :put ($"i"->"script") }
<two empty lines eated by forum engine>
[admin@df.router] > :local "nothing"; :put [typeof $"nothing"]; /system/script/job/print where script!=$"nothing"
nothing

NOT EXPECTED (!!!):

Columns: OWNER, STARTED
# OWNER STARTED
0 admin may/06/2023 08:06:38
1 admin may/06/2023 08:22:44
Screenshot_1.jpg
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One more strange issue (nothing is NOT nothing?)

Sat May 06, 2023 4:57 pm

A river of false assumptions and beliefs that leads nowhere.

Fact:
nothing is not equal to ni and is not equal to empty string, and is one reserved word.
nil is not equal to nothig and is not equal to empty string, and is not one reserved word.
"" is one empty string, and OBVIOUSLY is not nothing and also is not nil

This is valid in any programming language, not just RouterOS scripting.
(I don't know if there is some language that makes them equivalent, but I doubt it...)

where script!="" mean where script (is) not equal (to) empty string,
and OBVIOUSLY return all the job on example because all do not have empty string as script value.

The "script" value on the example are "nil".

The correct syntax is this:
/system script job print where [:typeof $script]!="nil"

And a correct test is this:
/system script job ; :foreach item in=[find] do={:put [:typeof [get $item script]]}

So, all "NOT EXPECTED" and "should be" on your topic are wrong, because they are based on your false beliefs and assumptions.

P.S.: print is used to print on the terminal, not to manage values within a script
(for completeness: only a few exceptions are necessary due to the laziness of MikroTik programmers, but it is not for this case).
 
dfdf
newbie
Topic Author
Posts: 36
Joined: Wed Dec 08, 2021 3:51 pm

Re: One more strange issue (nothing is NOT nothing?)

Wed May 10, 2023 5:06 pm

Well, to be short,
/system script job print as-value detail
return array of values where all nil values are converted to nothing... Not obvious, but thanx for clearing this out.

PS. print as-value result is NOT printed on terminal... only if used with
:put [/system script job print as-value detail]
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One more strange issue (nothing is NOT nothing?)

Wed May 10, 2023 6:34 pm

Again false assumptions:

They aren't converted to "nothing", they just don't exist in print as-value.
:put [/system script job print as-value]

:put [/system script job print as-value detail]
And calling a value inside an array, which doesn't exist, returns "nothing".

example 7.10beta5 code

[admin@test] > :put [/system script job print as-value]
.id=*41;.nextid=*47;owner=admin;started=1970-02-02 02:14:00;
.id=*47;owner=admin;started=1970-02-02 02:14:14
[admin@test] > 
[admin@test] > :put [/system script job print as-value detail]
.id=*41;.nextid=*49;owner=admin;policy=local;telnet;ssh;ftp;reboot;read;write;policy;test;winbox;password;web;sniff;sensitive;api;romon;rest-api;started=1970-02-02 02:14:00;type=login;
.id=*49;owner=admin;policy=local;telnet;ssh;ftp;reboot;read;write;policy;test;winbox;password;web;sniff;sensitive;api;romon;rest-api;started=1970-02-02 02:14:15;type=command
[admin@test] > 

[admin@test] > :put ([:toarray "test0,test1"]->1) 
test1
[admin@test] > :put ([:toarray "test0,test1"]->2) 

[admin@test] > :put [:typeof ([:toarray "test0,test1"]->2)] 
nothing
[admin@test] > 
 
dfdf
newbie
Topic Author
Posts: 36
Joined: Wed Dec 08, 2021 3:51 pm

Re: One more strange issue (nothing is NOT nothing?)

Thu May 11, 2023 4:19 pm

ok, but how will You explain this:
:put [:typeof []]
nil
If we have launched a simple script with
:delay 60s

Not working (while above script is running):
/system script job print where $"script"=[]
:put [:len [/system script job find where $"script"!=[]]]
0
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One more strange issue (nothing is NOT nothing?)

Thu May 11, 2023 4:43 pm

Still?
Isn't that enough for you?
/system script job print where [:typeof $script]!="nil"
The correct way is this and it is perfectly useless to look for bullshit.

Aren't people so stupid that to do 6 * 10 + 4 they make a loop where they add 10 times 6 and another loop for add 4 times 1, OR NOT?
 
dfdf
newbie
Topic Author
Posts: 36
Joined: Wed Dec 08, 2021 3:51 pm

Re: One more strange issue (nothing is NOT nothing?)

Thu May 11, 2023 7:48 pm

that's emotional reply with no meaningful explanation. Please avoid wording "bullshit" and so. The question is NOT NONSENSE, it's the attempt to understand, but not to listen to things like your last post. Don't want to explain - your right, but leave your emotions aside this place please, 'guru'.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: One more strange issue (nothing is NOT nothing?)

Thu May 11, 2023 7:53 pm

Please leave the forum tag out of context.

The explanation is simple, RouterOS doesn't compare well two objects that don't exist when you make them do things that don't make sense.
How do you compare one object that doesn't exist with another?

[] is = [] because are two identical nil,
$scipt (when is nil) is unexpected the coparision with another nil that is not the same...
4 and 3 are two numbers, but are not the same things...

Who is online

Users browsing this forum: mstanciu and 84 guests