Community discussions

MikroTik App
 
Chiara
newbie
Topic Author
Posts: 47
Joined: Thu Jul 23, 2015 3:47 pm

Fail Variable declaration sintax from manual

Fri Dec 04, 2020 4:34 pm

Hi,

If i copy and paste this code on a terminal of CCR1009 with routeros 6.47.7 it fails, but on the manual it says it it the correct sintax https://wiki.mikrotik.com/wiki/Manual:S ... #Variables:
:local myVar;
:set myVar "my value";
:put $myVar;
log info $myVar
this is the output from the terminal:
admin@Router] > :local myVar;
[admin@Router] > :set myVar "my value";
syntax error (line 1 column 6)
[admin@Router] > :put $myVar;
What is wrong here, why can't I set my value to myvar?
 
msatter
Forum Guru
Forum Guru
Posts: 2012
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Fail Variable declaration sintax from manual

Fri Dec 04, 2020 4:39 pm

:set $myVar "my value";
Loving my freedom and so, no Twitter, no Facebook/Instagram/WhatsApp, no Apple and no Google/Alphabet.

Running:
RouterOS 6.48 / Winbox 3.27 64bits
 
Chiara
newbie
Topic Author
Posts: 47
Joined: Thu Jul 23, 2015 3:47 pm

Re: Fail Variable declaration sintax from manual

Fri Dec 04, 2020 5:03 pm

Thank you, you've saved "half" of my day, hope mikrotik will fix it also in the wiki.
Now the var can be set, but next row :put alway is empty.
Last edited by Chiara on Fri Dec 04, 2020 5:59 pm, edited 1 time in total.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 6176
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Fail Variable declaration sintax from manual

Fri Dec 04, 2020 5:53 pm

local variable lives only inside scope, and each command line is in its own scope.
Either put whole script in curly braces or use global variable

and :set $var value does not solve the actual problem either.
 
Chiara
newbie
Topic Author
Posts: 47
Joined: Thu Jul 23, 2015 3:47 pm

Re: Fail Variable declaration sintax from manual

Fri Dec 04, 2020 6:02 pm

Thank you, this way all seems to work:
 [ :set $myVar "my value"; log info $myVar ]
 
User avatar
eworm
Forum Veteran
Forum Veteran
Posts: 749
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Fail Variable declaration sintax from manual

Sat Dec 19, 2020 12:49 am

You should use curly brackets, not square brackets. So correct code:
{ :local myVar; :set myVar "my value"; :log info $myVar; }
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1874
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Fail Variable declaration sintax from manual

Sun Dec 20, 2020 5:14 pm

Or
{ 
  :local myVar
  :set $myVar "Some data"
  :put $myVar
  :log info $myVar
}
Both :set myVar "my value" and :set $myVar "my value" does work fine.
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 

Who is online

Users browsing this forum: eworm, jvzg545cr and 19 guests