# Can somebody explain how this script works?

**URL:** <https://forum.mikrotik.com/t/can-somebody-explain-how-this-script-works/163411>\
**Category:** Scripting\
**Created:** [January 8, 2023, 11:48am UTC](https://forum.mikrotik.com/t/can-somebody-explain-how-this-script-works/163411 "2023-01-08T11:48:27Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [January 9, 2023, 12:14am UTC](https://forum.mikrotik.com/t/can-somebody-explain-how-this-script-works/163411/5 "2023-01-09T00:14:40Z")

</div>

How define dynamic variables:  
[http://forum.mikrotik.com/t/concatenate-values-to-create-variable-name/151793/2](http://forum.mikrotik.com/t/concatenate-values-to-create-variable-name/151793/2)  
  
  
You do not specify where you try to run this “script”, I assume the Terminal at this point.

Script analysis. part one:

```plaintext
:local cookie "someName";
:local cookieCode do={
 :put "TestIt";
 /system routerboard print;
};

[[:parse (":global ".$cookie)]];
[[:parse (":global ".$cookie."; :set \$".$cookie." (\"\");")]];

/system script environment remove [find where name=$cookie];

```

1. remove all frills
2. replace long chain of statements like “1 + 1 + 1 + 1 + 1” with a chain that does the same thing, but shorter like “1 × 5” (just an example)
3. fix $ error after :set and added missing { } for terminal.  
  
  

```plaintext
{
:local cookie "someName"

:local cookieCode do={:put "TestIt"; /system routerboard print}
# create a function called cookieCode and the function do what is present between the { }

[[:parse ":global $cookie"]]
# is like >:global someName<
# what this do: on parse session define global variable someName with "nothing" value
 
[[:parse ":global $cookie; :set $cookie \"\""]]
# is like >:global someName; set someName ""<
# what this do: on parse session define global variable someName with "nothing" value,
# and later set someName global variable = to "" (empty string)

/system script environment remove [find where name=$cookie]
# what this do: remove global variable "someName" from environment
}

```

**But we don’t give a damn about all this** , in reality what we notice is that **the function is called even if it is never written to use it** :

For extremely synthesize the compiler bug:  
[9b184@MATRIX] \> :local test do={:put “WHY\3F\3F\3F”};;  
WHY???  
[9b184@MATRIX] \>

Part two is just the same as part one, just multiplied:  
{  
:local test1 do={:put “test1”}  
:local test2 do={:put “test2”}  
:local test3 do={:put “test3”}  
:local test4 do={:put “test4”}  
:local test5 do={:put “test5”}  
  
  
}  
on second call all function defined before are executed…  
  
  
**Temporary (I hope) fix**: assign the returned value to one useless variable:

```plaintext
{
:local cookie "someName"

:local cookieCode do={:put "TestIt"; /system routerboard print}

:local useless [[:parse ":global $cookie"]]
 
:local useless [[:parse ":global $cookie; :set $cookie \"\""]]

/system script environment remove [find where name=$cookie]
}

```

Tested on 6.48.6 and 7.6

---

_[View the full topic](https://forum.mikrotik.com/t/can-somebody-explain-how-this-script-works/163411)._
