我有若干的 cmd 檔(維護網路設備的指令檔)
其中一個檔案內容如下
port,vlan
sh circuit count %port% vlan-id %vlan% live
conf
port eth %port%
dot pvc %vlan%
no shutdown
我想要的結果是
當 cmd檔 的第一行被賦予值的時候
第一行之後(指令)
會被變數值取代
以上可面的例子
假設我賦予
port = 12/1
vlan = 3999
結果為
sh circuit count 12/1 vlan-id 3999 live
conf
port eth 12/1
dot pvc 3999
no shutdown
上面的結果就可以丟入設備去執行
我有針對上面的例子去寫出來
但是 cmd 檔案有很多
每個 cmd 的第一行也都不一樣
請問要怎麼寫出可變的方式
規則就是
【1】cmd 的第一行皆為整個 cmd 的變數
【2】第一行 的變數在其它行會用 %變數%
謝謝大家
Cisco IOS.sh Variables
An Cisco IOS.sh variable is a way to simplify typing tasks and use long text or functions in a short symbol. Cisco IOS.sh variables can be created in EXEC mode. There cannot be any spaces between the variable name and the equal sign.
Creating a Variable
To create a variable name, use NAME=value with no space:
Router# VAR1=value1
Router# VAR2=value2
To retrieve the configuration state of the Cisco IOS.sh variables:
Router# show shell environment
VAR1=value1
VAR2=value2
To remove a variable, simply assign an empty value to the variable:
Router# VAR1=
Cisco IOS.sh variables are associated with a user's login session, so the Cisco IOS.sh variable set by one user is not visible to others.
Variable Substitution in CLI
A variable reference is done by using the "$" character in front of the name of the variable:
Router# abc=123
Router# echo $abc