Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
Shell 如何将值从子expect脚本返回到父脚本_Shell_Unix_Expect - Fatal编程技术网

Shell 如何将值从子expect脚本返回到父脚本

Shell 如何将值从子expect脚本返回到父脚本,shell,unix,expect,Shell,Unix,Expect,我在shell脚本中有一个expect脚本。我的问题是无法从子expect脚本到shell父脚本获取变量值 请在下面找到我的代码: #!/bin/sh expect <<- DONE spawn telnet myemailserver.com imap expect "* OK The Microsoft Exchange IMAP4 service is ready." send "a1 LOGIN myuser mypass\r" expect "a1 OK LOGIN c

我在shell脚本中有一个expect脚本。我的问题是无法从子expect脚本到shell父脚本获取变量值

请在下面找到我的代码:

#!/bin/sh

expect <<- DONE
spawn telnet myemailserver.com imap
expect "* OK The Microsoft Exchange IMAP4 service is ready."

send "a1 LOGIN myuser mypass\r"
expect "a1 OK LOGIN completed."

send "a2 EXAMINE INBOX\r"
expect "a2 OK EXAMINE completed."

send "a3 SEARCH UNSEEN\r"
expect "a3 OK SEARCH completed."
set results $expect_out(buffer)
set list [split $results "\n"]

send "a4 LOGOUT\r"
expect "Connection closed by foreign host."

spawn echo $list

expect eof
DONE

echo $list
exit 0
#/垃圾箱/垃圾箱

expect在脚本被提供给expect解释器之前,您的here文档要进行shell变量扩展。
$list
变量被零替换(假设程序中还没有名为list的shell变量)。您需要确保此处的单据是单引号(如下所示)

与使用awk或sed一样,shell进程间通信是通过沿标准IO通道传递数据来执行的:shell脚本必须捕获expect程序的输出:

list=$( expect <<'END'
    log_user 0         
    # expect program here
    puts $list
END
)
echo $list
list=$(预期