Expect:如何将执行环境导出到运行环境? (发送密钥的地方)
Expect: How does one export the executing environmt to the runtime environment? (where keys are sent)
我试过以下方法:
set timeout -1
spawn $env(SHELL)
match_max 100000
send -- "ssh somewhere@addr"
expect "*"
for { set i 0 } { $i < [array size env] } { incr i } {
send -- "echo env($i) = $env($i)"
expect "*"
}
send -- "env > foo\r"
expect "*"
send -- "^D"
expect eof
以上失败并出现以下错误:
no such variable
(read trace on "::env(0)")
invoked from within
"send -- "echo env($i) = env($i)""
("for" body line 2)
invoked from within
"for { set i 0 } { $i < [array size env] } { incr i } {
send -- "$::env($i)"
expect "*"
}"
(file "./script.exp" line 52)
我将通过重新获取 rc
文件来解决系统问题;我只是想将我设置的未知变量集合(相对于脚本)传输到远程执行环境。
这可以吗,我对TCL不熟悉(新手)?
Tcl arrays 更像是键和值的字典,而不是按数字索引的列表。您可以使用 [array names env]
获取键列表并使用 foreach
:
遍历它们
foreach n [array names env] {
send -- "echo env($n) = $env($n)\r"
expect "\n"
}
我试过以下方法:
set timeout -1
spawn $env(SHELL)
match_max 100000
send -- "ssh somewhere@addr"
expect "*"
for { set i 0 } { $i < [array size env] } { incr i } {
send -- "echo env($i) = $env($i)"
expect "*"
}
send -- "env > foo\r"
expect "*"
send -- "^D"
expect eof
以上失败并出现以下错误:
no such variable
(read trace on "::env(0)")
invoked from within
"send -- "echo env($i) = env($i)""
("for" body line 2)
invoked from within
"for { set i 0 } { $i < [array size env] } { incr i } {
send -- "$::env($i)"
expect "*"
}"
(file "./script.exp" line 52)
我将通过重新获取 rc
文件来解决系统问题;我只是想将我设置的未知变量集合(相对于脚本)传输到远程执行环境。
这可以吗,我对TCL不熟悉(新手)?
Tcl arrays 更像是键和值的字典,而不是按数字索引的列表。您可以使用 [array names env]
获取键列表并使用 foreach
:
foreach n [array names env] {
send -- "echo env($n) = $env($n)\r"
expect "\n"
}