-3

I have a list which contains 72.xx.xxx.xxx 72.xx.xxx.xxx (There are some spaces ) I have a variable say var

Now I have to execute a command for $var times and I have to use "72.xx.xxx.xxx" each time. let us say the command is : "reset vpn $IP".

I have to execute the above command say two times (stored in variable) and for two IP address stored in list. Can any one help with TCL code? Thanks in advance.

4

1 回答 1

2

这真的是一个家庭作业。并且任务规范缺少一些重要的细节。

如果要遍历列表中的所有IP,只需执行

set ips {72.xx.xxx.xxx 72.xx.xxx.xxx}
foreach ip $ips {
  reset vpn $ip
}

如果您向ips列表中添加更多值,则该foreach命令将对所有剩余元素进行更多次迭代。

如果你想迭代,比如说,前 N 个元素,只需一个一个地选择它们:

set ips {72.xx.xxx.xxx 72.xx.xxx.xxx 72.xx.xxx.xxx 72.xx.xxx.xxx ...}
set ntimes 2
for {set ix 0} {$ix < $ntimes} {incr ix} {
  reset vpn [lindex $ips $ix]
}

等等。

没有火箭科学。只需阅读教程,阅读本书,在您真正尝试自己之前,请尽量避免提出这些简单的问题。

于 2012-07-10T12:18:42.497 回答