error because is missing the $ at the start of variable
{{{... :set ghwname [ /system routerboard get board-name; ];
Tik] > :set ghwmodel [ /system routerboard get model; ];
------1234567890^ column 10
[admin@MikroTik] > /system script add name=rosinit source={
{... :global ghwmodel;
{... :global ghwname;
{...
{... :global fdeviceconfig do={
{{... :if ([ /system routerboard get routerboard; ] = true) do={
{{{... :set ghwname [ /system routerboard get board-name; ];
syntax error (line 7 column 10)
[admin@MikroTik] > :set ghwmodel [ /system routerboard get model; ];
syntax error (line 1 column 10)
some corrections:
/system script
add name=rosinit dont-require-permissions=no owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source={
:global ghwmodel
:global ghwname
:global fdeviceconfig do={
:if ([/system routerboard get routerboard] = true) do={
:set $ghwname [/system routerboard get board-name]
}
}
}
corrections:
:if ([ /system routerboard get routerboard
; ] = true) do={
; inside a "condition", is still working, but logically cause fatigue to read
{{{... :set
$ghwname [ /system routerboard get board-name
; ]
;
; inside a "set", missing $, is still working with ; , but logically cause fatigue to read
removed all useless
;
use of $ (not full list):
:global variable value - no $ needed
:local variable value - no $ needed
:set $variable value - $ is needed
(3 + $variable) - $ is needed
$"variable-with-minus-on-name" - $ is needed, but also the quotes because the variable name contain -
string = "the variable x is $variable" - can put directly inside on string, $variable are replaced accordingly.
string = "the routerboard name is $[/system routerboard get board-name]" - $ can be used for evaluate a command and give the results as a string
other corrections:
:if ($ghwname = "cAP ac") do={ :set grole "wap"
; }
;
must be
:if ($ghwname = "cAP ac") do={:set
$grole "wap"}
$fsay severity=info message=("Hardware: " . $ghwname . " (" . $ghwmodel . " " . [ /system routerboard get revision; ] . ")")
;
must be
$fsay severity=info message="Hardware: $ghwname ($ghwmodel $[/system routerboard get revision])"