【问题标题】:Automatically press Enter to continue in Bash在 Bash 中自动按 Enter 键继续
【发布时间】:2012-06-26 17:57:08
【问题描述】:

我想更改 RSA 密钥以毫无问题地打开 ssh 连接。如果我使用this tutorial,它工作正常,但我想在 bash 脚本中完成。不幸的是,我被要求输入密码(我不想输入任何内容)。当脚本到达这一点时,如何实现自动连续按 Enter 三次?

This thread 没有帮助,因为我不允许在我的工作 PC 上安装新程序,而 echo | command 技巧似乎只对一个 Enter 有效。如果程序已经完成,我还需要输入“n”和 Enter,以免覆盖任何文件。我如何做到这一点?

【问题讨论】:

  • 如果您需要两个新行,请使用echo -e "\n"

标签: bash input enter


【解决方案1】:

如果你只需要按 Enter 很多次就可以了:

yes "" | command

对于任何比这更复杂的事情,您可能希望按照另一个线程中的建议使用 expect,您可以在没有 root 权限的情况下将其安装在您的 homedir 中。

PS:请避免将来重新发布问题。如果您由于某种原因不喜欢某个答案,请发表评论。

【讨论】:

    【解决方案2】:

    如果您只想在 bash 脚本中创建 ssh 密钥而不需要任何用户输入,您可以为 ssh-keygen 指定参数:

    # rsa type (default), no passphrase, write to file id_rsa and id_rsa.pub
    captain:~> ssh-keygen -t rsa -N "" -f id_rsa
    Generating public/private rsa key pair.
    Your identification has been saved in id_rsa.
    Your public key has been saved in id_rsa.pub.
    The key fingerprint is:
    fe:4a:82:08:0e:ab:b7:02:62:11:4d:3e:79:a4:d3:98 mrb@captain.local
    

    【讨论】:

      猜你喜欢
      • 2020-09-23
      • 2010-10-28
      • 2013-12-08
      • 2010-11-27
      • 1970-01-01
      • 2010-11-23
      • 2023-03-22
      • 2014-04-18
      相关资源
      最近更新 更多