shell的多个输入

时间:2014-01-15 06:54:37

标签: shell scripting

在尝试编写应自动提供输入的shell脚本时遇到了困难。

运行例如:adpatch.sh

的脚本时

它提示多个输入,如:

Do you currently have files used for installing or upgrading the database
installed in this APPL_TOP [YES] ? need to give input here


Do you currently have Java and HTML files for HTML-based functionality
installed in this APPL_TOP [YES] ? need to give input here


Do you currently have Oracle Applications forms files installed
in this APPL_TOP [YES] ? need to give input here


Do you currently have concurrent program files installed
in this APPL_TOP [YES] ? need to give input here

所以不使用命令行参数,有没有其他方式自动输入? 在此先感谢。

1 个答案:

答案 0 :(得分:1)

我相信expect就是你想要的。您可能需要先安装它(基于Debian / Ubuntu的Linux发行版的“apt-get install expect”)。

期望具有将回答与特定问题配对的优势,而不是盲目回答“是”。

来自man page

  

通常,Expect对于运行任何需要的程序非常有用   程序和用户之间的交互。一切都是必要的   是可以通过编程方式表征交互。期望   也可以给用户后退控制(不停止程序   如果需要的话。同样,用户可以将控制权返回给   脚本随时“。