Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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
Regex 将文件中读取行的一部分转换为tcl中的变量_Regex_File_Tcl_Expect - Fatal编程技术网

Regex 将文件中读取行的一部分转换为tcl中的变量

Regex 将文件中读取行的一部分转换为tcl中的变量,regex,file,tcl,expect,Regex,File,Tcl,Expect,我有一个这样的文件: IPLIST: 10.10.10.1 10.10.10.2 # A bunch of IPs #CMDS: ping $ip 我想使用tcl读取文件并运行命令。 我已经成功地读取了文件,创建了IP列表,还创建了命令列表。 我想运行命令,为此我做了: #iplist is the list of IP formed from IPLIST in file foreach ip $iplist { # cmdlist is the list of commands rea

我有一个这样的文件:

IPLIST: 10.10.10.1 10.10.10.2 # A bunch of IPs

#CMDS:
ping $ip
我想使用tcl读取文件并运行命令。 我已经成功地读取了文件,创建了IP列表,还创建了命令列表。 我想运行命令,为此我做了:

#iplist is the list of IP formed from IPLIST in file
foreach ip $iplist {
 # cmdlist is the list of commands read from file
 foreach cmd $cmdlist {
  echo "$cmd\n"
 }
}
我原以为命令中的$ip将在第一个foreach循环中被ip变量替换。但事实并非如此。我得到的是:

ping$ip

当我运行foreach循环时,有没有一种方法可以将文件中的$ip从iplist转换为ip? 我看了很多例子,但是没有一个可以在这种情况下使用 谢谢你的帮助

尝试使用:

它将对变量执行替换。我还使用了
-nobackslashes
-nocommands
,以防万一,可能有一些方括号不是您想要执行的,如果有的话,但是如果您确实想要执行,那么您可以省略它们。

尝试使用:

它将对变量执行替换。我还使用了
-nobackslashes
-nocommands
,以防万一,可能有一些方括号不是您想要执行的,如果有的话,但是如果您确实想要执行,那么您可以省略它们

echo [subst -nobackslashes -nocommands $cmd]