如何在没有用户交互的情况下使用 APT 安装软件包?

에이바*_*에이바 9 bash kernel aptitude apt debian-squeeze

我有一个脚本可以下载和替换 Debian 压缩中的内核头文件。

function fixHeaders(){
    #Replace the kernel headers from OVH with standard kernel headers...
    aptitude -y install linux-image-2.6.32-5-amd64  
    sed s/'GRUB_DEFAULT=0'/'GRUB_DEFAULT=1'/g
    update-grub
    echo "Rebooting the machine. Run this script again after reboot and choose option 2."
    sleep 1
    reboot  
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是,在 aptitude 下载软件包后,它会将脚本放入文本 gui 并询问用户一堆问题。有什么办法可以跳过这个或在适当的时间发送选项卡/输入来为所有答案选择“确定”?

에이바*_*에이바 11

根据 Daniel t 的评论,我能够做到这一点 DEBIAN_FRONTEND=noninteractive

DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get install -y -q --force-yes linux-image-2.6.32-5-amd64 
Run Code Online (Sandbox Code Playgroud)