Community discussions

MUM Europe 2020
 
User avatar
astounding
Member Candidate
Member Candidate
Topic Author
Posts: 121
Joined: Tue Dec 16, 2008 12:17 am

Can someone explain this?

Mon Dec 08, 2014 10:19 pm

Now to try something I'm not sure will even work (running RouterOS 6.23):
[user@mikrotik] /system script environment> {:local x do={:put "Hi $1"};[$x "Mom"];:set x [:parse ":put \"Hello \$1\""];[$x "Dad"]} 
Hi Mom
Hello Dad
Hi 
The "Hi Mom" first output line is exactly what I expected (as documented). Good. Setting the local variable $x to the output of the :parse command in hopes that the resulting code value could be executed with a numbered argument, I wasn't sure that would work. But it DID work, resulting in "Hello Dad" in output line 2.

Can anyone explain the third line of output? Yeah, that's the one that's got me puzzled.
 
User avatar
skot
Long time Member
Long time Member
Posts: 586
Joined: Wed Nov 30, 2011 3:05 am

Re: Can someone explain this?

Tue Dec 09, 2014 2:33 am

That weird.

You can get rid of it by un[bracket]ing one or both of the called functions:
{:local x do={:put "Hi $1"};$x "Mom";:set x [:parse ":put \"Hello \$1\""];$x "Dad"}
After a bit of testing, looks like the first one you bracket is then re-echoed without the argument, after the next bracketed one.
{
:local x do={:put "Hi $1"}
$x "Mom"
:set x [:parse ":put \"Hello \$1\""]
[$x "Dad"]
:set x [:parse ":put \"Yo \$1\""]
$x "Sista"
:set x [:parse ":put \"Later \$1\""]
[$x "Bro"]
}
output:
Hi Mom
Hello Dad
Yo Sista
Later Bro
Hello

Example 2:
{
:local x do={:put "Hi $1"}
$x "Mom"
:set x [:parse ":put \"Hello \$1\""]
[$x "Dad"]
:set x [:parse ":put \"Yo \$1\""]
[$x "Sista"]
:set x [:parse ":put \"Later \$1\""]
$x "Bro"
}
output:
Hi Mom
Hello Dad
Yo Sista
Hello 
Later Bro
Conclusion: don't use brackets :D
I don't need any karma... I have Ιησους Χριστος!

Who is online

Users browsing this forum: No registered users and 6 guests