我在 shell 脚本中有一个期望脚本。我的问题是我无法从子期望脚本到 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
我发现最后一行的变量列表是空的。有没有办法将变量 $list 的值传递给 shell 父脚本?