When I import a rsc file, the code executed can't access global variables defined in the rOS main /env .
And the script can neither access variables defined in a subscript (loaded by a /import within the import script).
Here's my test code:
Code: Select all
[admin@MikroTik] > /file print detail where name~"test"
0 name="test.rsc" type="script" size=504 creation-time=jan/03/2002 00:12:20
contents=
#Cmd to run before importing this rsc file: :global GlobalVar "VALUE_of_GlobalVar"
:put "GlobalVar value is: $GlobalVar"
:put "Importing test-inc.rsc..."
/import test-inc.rsc\t
:put "SubScriptGlobalVar value is: $SubScriptGlobalVar"
:global ImportedScriptGlobalVar "VALUE_of_ImportedScriptGlobalVar"
:put "Just defined var ImportedScriptGlobalVar with value: $ImportedScriptGlobalVar"
#Cmd to run after importing this rsc file: :put "ImportedScriptGlobalVar value is: $ImportedScriptGlobalVar"
1 name="test-inc.rsc" type="script" size=135 creation-time=jan/03/2002 00:12:20
contents=
:global SubScriptGlobalVar "VALUE_of_SubScriptGlobalVar"
:put "Just defined var SubScriptGlobalVar with value: $SubScriptGlobalVar"
Code: Select all
[admin@MikroTik] > /import test.rsc
GlobalVar value is:
Importing test-inc.rsc...
Just defined var SubScriptGlobalVar with value: VALUE_of_SubScriptGlobalVar
Script file loaded and executed successfully
SubScriptGlobalVar value is:
Just defined var ImportedScriptGlobalVar with value: VALUE_of_ImportedScriptGlobalVar
Script file loaded and executed successfully
Test done on rOS 6.29 and 6.30.4, on a RB951G-2HnD.
BTW, as shown below, it appears that $SubScriptGlobalVar, which is defined in the subscript test-inc.rsc and not readable within test.rsc, is well propagated to the upper level at the prompt.
Code: Select all
[admin@MikroTik] > :put "ImportedScriptGlobalVar value is: $ImportedScriptGlobalVar"
ImportedScriptGlobalVar value is: VALUE_of_ImportedScriptGlobalVar
[admin@MikroTik] > :put "SubScriptGlobalVar value is: $SubScriptGlobalVar"
SubScriptGlobalVar value is: VALUE_of_SubScriptGlobalVar
What a strange behavior !!!
Is this a bug, a known (undocumented ?) limitation, or am I missing something ???
In http://wiki.mikrotik.com/wiki/Manual:Sc ... #Variables , I read: "global - accessible from all scripts created by current user, defined by global keyword"
Thanks for your attention and feedbacks.
Fabrice