variable behavior inside of a script?

What in the world am I doing wrong here. Here’s an example of what I’m dealing with. (this is just an example, I know I can do [/system identity get name])

global variable systemIdent that is equal to “Jim’s Mikrotik”

From terminal:
:put [$systemIdent]

prints “Jim’s Mikrotik” --(without quotes)

In a script:
:put [$systemIdent]

prints syntax error ( line 1 column 8 )

Eventually I’m trying to write a file with some variables in it, but no matter WHAT I do, it’s like any global variable isn’t recognized inside a script. I’ve tried different syntax combinations for hours trying to figure this out. There is only 1 user account in the router, and the global variables are definitely set to the same user as the script. If I print the script out in terminal, the “s” in “systemIdent” is highlighted as an unrecognized word/command. I’ve tried $, brackets, $ in brackets, brackets with $ inside, brackets with $ inside of parenthesis, inside and outside of quotes, etc.

Obviously I’m missing something. What is it?

Where is it printing this error when you run it in a script?


Are you declaring the global variable within the script? This does not change the variable value, but is necessary to access the variable ( http://forum.mikrotik.com/t/script-text-runs-on-terminal-but-not-from-run-script/61673/1)

:global systemIdent
/log info "$systemIdent"

That was it! Haha. Thanks.

Also, the thread you linked to just says “try this” with an example but there is no explanation. I had already read that thread, but your explanation of ‘this does not change the variable value…’ was an important addition…

Thx,
Jim