【发布时间】:2014-04-21 12:33:02
【问题描述】:
如果我将期望编码到 shell 脚本中,我将无法获取 $expect_out(buffer) 和 $expect_out(0,string) 的值。
以下是我编写的示例代码。
[Linux Dev:upncommn ~]$ cat expshl.sh
#!/bin/bash
expect << EOF
spawn "/home/upncommn/expectecho.sh"
expect {
"hi" { send_user "You said_hi $expect_out(buffer)\n";
send_user "Sting $expect_out(0,string)\n"
exit 1
}
"*bd*" { send_user "You said $expect_out(buffer)\n"
send_user "Sting $expect_out(0,string)\n"
exit 2
}
timeout { send_user "timeout\n"; exit 3 }
}
EOF
[Linux Dev:upncommn ~]$ cat expectecho.sh
echo "hello"
echo "abduls"
echo "theos"
echo "this is abdul"
[Linux Dev:upncommn ~]$ ./expshl.sh
spawn /home/upncommn/expectecho.sh
hello
abduls
theos
You said (buffer)
Sting (0,string)
[Linux Dev:upncommn ~]$ echo $?
2
请帮我获取 $expect_out(buffer) 和 $expect_out(0,string)。
【问题讨论】:
标签: linux bash shell unix expect