四種變數 global - 定義全域變數, 可以要所有的腳本中調用共用 local - 定義本地變數,只能在其所要的腳本下調用,不能被其它腳本共用 loop index variables - 定義在for或foreach裡的索引號變數 monitor variables - 監視變數
ROS算術操作 - 負號;相減。 ! 邏輯非。 / 相除。 . 連接。兩個符串的連接,添加元素到清單 ^ 異或(XOR) ~ 取反 * 相剩 & 與(AND) && 邏輯與 + 相加 < 小於 = 大於等於 >> 向右位移 | 或 || 邏輯或
ROS說明書裡的例子:
計算順序 [admin@MikroTik]> :put (10+1-6*2=11-12=2+(-3)=-1) false [admin@MikroTik]> :put (10+1-6*2=11-12=(2+(-3)=-1)) true
邏輯非 [admin@MikroTik]> :put (!true) false [admin@MikroTik]> :put (!(2>3)) true
數位取反 [admin@MikroTik]> :put (~255.255.0.0) 0.0.255.255
加法 [admin@MikroTik]> :put (3ms + 5s) 00:00:05.003 [admin@MikroTik]> :put (10.0.0.15 + 0.0.10.0) cannot add ip address to ip address [admin@MikroTik]> :put (10.0.0.15 + 10) 10.0.0.25
減法 [admin@MikroTik]> :put (15 - 10) 5 [admin@MikroTik]> :put (10.0.0.15 - 10.0.0.3) 12 [admin@MikroTik]> :put (10.0.0.15 - 12) 10.0.0.3 [admin@MikroTik]> :put (15h - 2s) 14:59:58
乘法 [admin@MikroTik]> :put (12s * 4) 00:00:48 [admin@MikroTik]> :put (-5 * -2) 10
除法 [admin@MikroTik]> :put (10s / 3) 00:00:03.333 [admin@MikroTik]> :put (5 / 2) 2 [admin@MikroTik]> :put (0:0.10 / 3) 00:00:02
比較 [admin@MikroTik]> :put (10.0.2.3 :put (100000s>27h) true [admin@MikroTik]> :put (60s,1d!=1m,3600s) true [admin@MikroTik]> :put (bridge=routing) false [admin@MikroTik]> :put (yes=false) false [admin@MikroTik]> :put (true=aye) false
邏輯與 AND, 邏輯或 OR [admin@MikroTik]> :put ((yes && yes) || (yes && no)) true [admin@MikroTik]> :put ((no || no) && (no || yes)) false
數位與AND, 或OR, 異或XOR [admin@MikroTik]> :put (10.16.0.134 & ~255.255.255.0) 0.0.0.134
位移操作 [admin@MikroTik]> :put (~((0.0.0.1 :put (1 . 3) 13 [admin@MikroTik]> :put (1,2 . 3) 1,2,3 [admin@MikroTik]> :put (1 . 3,4) 13,4 [admin@MikroTik]> :put (1,2 . 3,4) 1,2,3,4 [admin@MikroTik]> :put ((1 . 3) + 1) 14 [admin@MikroTik]> :set a "It\'s " [admin@MikroTik]> :put ($a . OK) It\'s OK
ROS腳本保留字 beep execute global list pick time toip typeof delay find if local put toarray tonum while do for led log resolve tobool tostr environment foreach len nothing set toid totime
:beep length=2s frequency=10000 產生2秒10kHz的音訊 length缺省值為100ms frequency缺省值為1000Hz
:set a "/int dis lan\n/int dis wan" :execute $a 執行多條命令,例子裡執行了兩條命令。\n是換行
:global 定義全域變數
:list interface 顯示相關命令。顯示目前的目錄及子目錄下有關interface的命令
:pick 取字串或陣列的某一斷。字串(陣列)的第一個為0。 [admin@MikroTik]>:put [:pick "I love you" 2 6] love
:time 執行命令所需的時間 [admin@MikroTik]> :put [:time [:resole www.sina.com.cn]] 00:00:00.006 執行解析www.sina.com.cn這個功能變數名稱所需的時間
toip toarray tonum tobool tostr toid totime 轉換數值型別
:delay 3 延時3秒,缺省為1秒
:find 查找字串或陣列中第一個出現查找內容的位置 [admin@MikroTik]>:put [:find abcdcba cd] 2 [admin@MikroTik]>:put [:find "1,2,3,4,3,2,1" 2] 1
:put 輸出到螢幕上,上面就很多例子了。
:if 條件選擇 [admin@MikroTik]>:if(1:if(1>2) do={:put true} else={:put flase} flase 如果條件為真,執行do={}裡面的命令,否則執行else={}裡有命令
:local 定義本地變數
:while 條件為真時迴圈執行do={}裡的指令碼命令 [admin@MikroTik]>:set i 0;:while($i :put [:resolve www.sina.com.cn] 61.172.201.240
:environment print 顯示所有變數及其值
:len 字串或陣列的長度 [admin@MikroTik] > :put [:len hello] 5 [admin@MikroTik] > :put [:len "1,2,23,65,54,6"] 6
:nothing 空值。nothing不等0,不等於空字元"" :find abc a的結果是0 :find abc d的結果是nothing
:set 賦值 [admin@MikroTik] > :set a test 將abc字元賦給變數a [admin@MikroTik] > :put $a test [admin@MikroTik] > :put a a 引用變數的值要在變數前面加$
|