You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SSM文档的Shell脚本中自动回应apt autoremove的Y确认?

解决apt autoremove自动确认的问题

你尝试用<<- Y自动回应确认提示无效,是因为这是Shell的here-doc语法,不适合处理这类交互式命令的确认请求。可以用以下两种方法解决:

方法1:使用apt自带的自动确认参数

apt命令本身提供-y参数,会自动确认所有交互式提示,直接修改命令即可:

schemaVersion: "2.2"
description: "Command Document Example JSON Template"
parameters:
  Message:
    type: "String"
    description: "Hello World!"
    default: "Hello"
mainSteps:
  - action: "aws:runShellScript"
    name: "HelloScript"
    inputs:
      runCommand:
        - "sudo apt autoremove nessusagent -y &&"
        - "sleep 20 &&"
        - "echo 'uninstallation completed!'"

方法2:用yes命令管道输入

如果场景特殊无法使用-y参数,可通过yes命令持续输出Y,通过管道传递给apt命令:

schemaVersion: "2.2"
description: "Command Document Example JSON Template"
parameters:
  Message:
    type: "String"
    description: "Hello World!"
    default: "Hello"
mainSteps:
  - action: "aws:runShellScript"
    name: "HelloScript"
    inputs:
      runCommand:
        - "yes | sudo apt autoremove nessusagent &&"
        - "sleep 20 &&"
        - "echo 'uninstallation completed!'"

推荐优先使用方法1,这是apt官方支持的自动确认方式,逻辑更清晰,也避免了不必要的输出。

内容的提问来源于stack exchange,提问作者Sai Teja Makani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 12:42:06