如何编写自动填充用户输入的 ksh 脚本?

发布于 2024-08-23 18:17:34 字数 152 浏览 14 评论 0 原文

有没有办法在 ksh 脚本中自动执行用户输入?

我意识到,在许多情况下,您可以创建一个 Expect 脚本来完全执行我所说的操作,但 Expect 未安装在服务器上,并且在不久的将来不可能发生这种情况。但我仍然需要一种自动执行用户输入的方法,因此唯一需要的反应就是启动脚本。

Is there any way to automate the user input in a ksh script?

I realize that in many instances you can create an expect script to do exactly what I am saying, but expect is not installed on the server and there is no chance of that occurring in the near future. But I still need a method of automating user input so the only reaction required is to start the script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆で 2024-08-30 18:17:34

如果您有完整的“用户”输入集,则可以重定向标准输入:
script.ksh

如果您有其中一些,或者动态生成它,您可以使用 “这里是” 文档。

如果您要解析提示,最简单的方法,正如您提到的,最简单的方法是使用 Expect。即使 Expect 在服务器上不可用,您也可以更轻松地包含必要的 Tcl/Expect 来进行解析,而不是重写和重新调试它。

If you have the complete set of "user" input, you can redirect stdin:
script.ksh <userinputfile

If you have some of it, or generate it on the fly, you can use "hereis" documents.

If you are going to be parsing prompts, the easiest way, as you mention, the easiest way is to use Expect. Even if Expect isn't available on the server, it'll be easier for you to include as much Tcl/Expect as necessary to do your parsing than to rewrite and redebug it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文