【问题标题】:Auto answer yes for command `gcloud compute instance-templates delete`对命令“gcloud compute instance-templates delete”自动回答是
【发布时间】:2019-07-12 02:29:48
【问题描述】:

要删除 gcloud 实例模板,我们调用

gcloud compute instance-templates delete TEMPLATE_NAME

但我们必须回答一个不适合自动化 bash 脚本的 Y/n 问题。我们想要自动回答是,如何?

附言

我的google search 对此问题的帮助不大。

该命令的手册页也没有任何其他参数。

gcloud help   compute instance-templates delete

【问题讨论】:

    标签: automation gcloud


    【解决方案1】:

    我同意在gcloud 命令的情况下使用--quiet 是最好的方法。

    但对于没有此类选项的 CLI 工具,我们可以显式使用 printf,如下所示:

    printf 'yes' | gcloud compute instance-templates delete TEMPLATE_NAME
    

    我希望这是有用的(如果不是在这种情况下,那么在其他地方)。

    【讨论】:

      【解决方案2】:

      gcloud 具有一组全局标志,包括 --quiet 以禁用此类提示:

      https://cloud.google.com/sdk/gcloud/reference/

      【讨论】:

      • 你点亮了我对 gcloud 的了解。谢谢!
      • 请注意,--quiet 将适用于该用例。但从语法上讲,它所做的是“关闭”所有提示和所有控制台输出——这可能是您不想要的。对于更通用的解决方案,下面@AmitYadav 显示的printf "yes" | 方法可能是首选。它将正常显示所有控制台输出,并在提示时提交值yes
      猜你喜欢
      • 2016-12-30
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 2016-07-03
      • 1970-01-01
      • 2016-06-03
      • 2016-12-23
      • 2021-04-02
      相关资源
      最近更新 更多