Awk 在expect send getting can';“我不读”;“1”节:没有这样的变量错误

Awk 在expect send getting can';“我不读”;“1”节:没有这样的变量错误,awk,tcl,expect,Awk,Tcl,Expect,我通过expect send发送awk命令,发送时出现错误,但无法读取1没有这样的变量 我确实使用了{{}机械系统,但我确实工作了 expect "$prompt" { send "awk {{print $1}} /mytest/test.log\r" } 我尝试了eascapse序列\,但除了(缓冲区)等,我没有找到任何响应 我也尝试过使用exec命令 expect "$prompt" { send "exec awk {{print $1}} /mytest/te

我通过expect send发送awk命令,发送时出现错误,但无法读取1没有这样的变量

我确实使用了{{}机械系统,但我确实工作了

expect "$prompt" {
    send "awk {{print $1}} /mytest/test.log\r"
}
我尝试了eascapse序列\,但除了(缓冲区)等,我没有找到任何响应

我也尝试过使用exec命令

    expect "$prompt" {
    send "exec awk {{print $1}} /mytest/test.log\r"
}

你必须使用大括号来避免替换。或者,你也必须避开美元符号和花括号

举几个例子:


1.与本地计算机上的程序交互:

#!/usr/bin/expect -d

spawn "/bin/bash"
set cmd "awk '\{print \$1\}' /mytest/test.log\r"
send $cmd
expect eof
puts $expect_out(buffer)

2.通过ssh与远程程序交互:

#!/usr/bin/expect -d

append cmd {awk '{print $1}' /mytest/test.log} "\r"
spawn ssh user@hostname
set prompt ":|#|\\\$"
interact -o -nobuffer -re $prompt return
send "mypassword\r"
interact -o -nobuffer -re $prompt return
send $cmd
send "exit\r"
expect eof
puts $expect_out(buffer)

你必须使用大括号来避免替换。或者,你也必须避开美元符号和花括号

举几个例子:


1.与本地计算机上的程序交互:

#!/usr/bin/expect -d

spawn "/bin/bash"
set cmd "awk '\{print \$1\}' /mytest/test.log\r"
send $cmd
expect eof
puts $expect_out(buffer)

2.通过ssh与远程程序交互:

#!/usr/bin/expect -d

append cmd {awk '{print $1}' /mytest/test.log} "\r"
spawn ssh user@hostname
set prompt ":|#|\\\$"
interact -o -nobuffer -re $prompt return
send "mypassword\r"
interact -o -nobuffer -re $prompt return
send $cmd
send "exit\r"
expect eof
puts $expect_out(buffer)