【问题标题】:TCL exec command loop Help (Cisco Router)TCL exec 命令循环帮助(Cisco 路由器)
【发布时间】:2014-10-29 17:52:25
【问题描述】:

我正在尝试连续循环 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
}

【问题讨论】:

    标签: loops tcl exec cisco


    【解决方案1】:

    没关系谷歌最终救了我:)

    if {[catch {ios_config "service internal"} result]} {
        puts "Invalid Command 1" 
    }
    
    set a ["test led system black"]
    set b ["test led system green-solid"]
    
    for {set x 0} {$x<20} {incr x} {
        exec $a
        exec $b
    }
    

    【讨论】:

    • 你可以使用foreach x {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20}。
    【解决方案2】:

    我希望您在回答中使用的方括号是一个错字。

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

    定义变量的方式不正确。 Tcl 将抛出相同的错误,除非您有一个名为 test led system black 的 proc。

    用方括号定义它们就像您提出问题的方式一样。

    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}
    

    记住,用大括号括起来会防止任何排序变量替换。

    除此之外,您为循环变量提供的内容很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-06
      • 2018-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      相关资源
      最近更新 更多