避免bash脚本等待用户输入Enter键

时间:2017-07-14 05:12:59

标签: linux bash unix mailx

我在bash脚本中输入了以下内容。

 echo "Please see attached file" | mailx -S smtp=$smtpServer -s "Subject of the mail" -a $logfile -r "sender@domain.com" receiver1@domain.com receiver2@domain.com

如果发送邮件没有错误,它的工作正常。但有时如果出现错误,mailx将显示错误消息并等待用户输入回车键(回车)。我想避免这种情况。不应该等待用户输入回车键。如何在bash脚本中执行此操作?

1 个答案:

答案 0 :(得分:0)

您可以使用expect命令查找匹配的文本并将值设置为键入命令。这将在看到文本时自动键入值。

以下问题的解决方案可能有用。 Linux - Bash & Expect

另请参阅。 http://sharadchhetri.com/2010/12/07/how-to-use-expect-in-bash-script/