Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops TCL exec命令循环帮助(Cisco路由器)_Loops_Tcl_Exec_Cisco - Fatal编程技术网

Loops TCL exec命令循环帮助(Cisco路由器)

Loops TCL exec命令循环帮助(Cisco路由器),loops,tcl,exec,cisco,Loops,Tcl,Exec,Cisco,我正在尝试连续循环2个命令,以使Cisco 891-F上的LED闪烁 这是我到目前为止所拥有的。我不熟悉使用foreach进行循环。也许还有别的办法,但我不知道。任何帮助都会很好 if {[catch {ios_config "service internal"} result]} { puts "Invalid Command 1" } set a "test led system black" set b "test led system green-solid" foreach {

我正在尝试连续循环2个命令,以使Cisco 891-F上的LED闪烁

这是我到目前为止所拥有的。我不熟悉使用foreach进行循环。也许还有别的办法,但我不知道。任何帮助都会很好

if {[catch {ios_config "service internal"} result]} { 
puts "Invalid Command 1" 
}

set a "test led system black"
set b "test led system green-solid"

foreach {a b} [list $a $b] {
exec $a
exec $b
}

不管谷歌最终拯救了我:)

如果{[catch{ios_config“service internal”}result]}{
放置“无效命令1”
}
设置[“测试led系统黑色”]
设置b[“测试led系统绿色固态”]

对于{setx0}{$x我希望您在回答中使用的方括号是一个拼写错误

set a ["test led system black"]
set b ["test led system green-solid"]
这不是定义变量的正确方法
Tcl
将抛出错误,除非您有一个名为
测试led系统黑色的过程

用外方括号定义它们就像你如何回答你的问题一样

set a "test led system black"
set b "test led system green-solid"
或者你可以用大括号

set a {test led system black}
set b {test led system green-solid}
记住,用大括号括起来可以防止任何排序变量替换


除此之外,您为循环变量所做的一切都很好。

您可以使用
foreach x{1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 19 20}
set a {test led system black}
set b {test led system green-solid}