bash 在expect{exp_continue}之后继续脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12264903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
continue script after expect{exp_continue}
提问by user788171
I have bash code that looks like the following:
我有如下所示的 bash 代码:
/usr/bin/expect -c '
spawn python Tools/python/install.py
expect {
-nocase "password:" {
send "$env(PASS)\r"
exp_continue
}
}
interact
'
This code seems to work except for the fact that after it submits the passwords, it hangs. After this block of code, there is more code I want to execute in my script. Is there a way to get expect to drop me back into the bash script to continue execution of lines below this block of code?
这段代码似乎可以工作,除了在提交密码后它挂起的事实。在这段代码之后,我想在我的脚本中执行更多代码。有没有办法让我回到 bash 脚本中以继续执行此代码块下方的行?
回答by Jonah Bishop
(Just to formally answer this question)...
(只是正式回答这个问题)...
I'm guessing the interactcommand is biting you. From the man page:
我猜这个interact命令正在咬你。从手册页:
interactgives control of the current process to the user, so that keystrokes are sent to the current process, and the stdout and stderr of the current process are returned.
交互将当前进程的控制权交给用户,以便将击键发送到当前进程,并返回当前进程的 stdout 和 stderr。
I would try either of these:
我会尝试以下任一方法:
- Remove the
interactcommand - Issue the command in the background using
&orscreen
- 删除
interact命令 - 使用
&或在后台发出命令screen
Based on your comment, it looks like the former was what worked.
根据您的评论,看起来前者是有效的。

