如何使 bash 脚本中的所有安装 apt 假设是并强制是

How to make apt assume yes and force yes for all installations in a bash script

我目前正在学习 linux 并想编写一个 bash 脚本来按照我想要的方式设置一台新机器。

为了做到这一点,我想在上面安装不同的东西等等

我在这里想要实现的是在 bash 脚本的顶部进行设置,这将使 apt 接受脚本执行期间提出的所有 [y/n] 问题

我要自动接受的问题示例:

After this operation, 1092 kB of additional disk space will be used. Do you want to continue? [Y/n]

我刚刚开始创建文件,所以这是我目前所拥有的:

#!/bin/bash

# Constants

# Set apt to accept all [y/n] questions
>> some setting here <<

# Update and upgrade apt
apt update;
apt full-upgrade;

# Install terminator
apt install terminator

apt 旨在交互使用。如果你想自动化,请查看 apt-get,尤其是它的 -y 选项:

-y, --yes, --assume-yes

Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactively. If an undesirable situation, such as changing a held package, trying to install an unauthenticated package or removing an essential package occurs then apt-get will abort. Configuration Item: APT::Get::Assume-Yes.

另请参阅 man apt-get 了解更多选项。

apt:

apt -o Apt::Get::Assume-Yes=true install <package>

参见:man aptman apt.conf

如果你确实想像你说的那样在文件的顶部设置一次然后忘记它,你可以使用 APT_CONFIG 环境变量。参见 apt.conf

echo "APT::Get::Assume-Yes=yes" > /tmp/_tmp_apt.conf
export APT_CONFIG=/tmp/_tmp_apt.conf

apt-get update
apt-get install terminator
...