我的脚本在使用 debootstrap 构建 debian 映像时,在 chroot 中用 systemd 替换 sysvinit。
由于这是一个“危险”的动作,apt-get 会问一个愚蠢的问题:“要继续,请输入短语‘是的,按我说的做!’”
我该如何编写脚本来回复该问题?
编辑:我尝试了所有 -y --yes --force-yes 选项,但它们不起作用。
答案1
奇怪的是,甚至似乎还问到--force-yes
:
apt-get remove -y --force-yes systemd
然而,
echo 'Yes, do as I say!' | apt-get remove systemd
工作顺利。
答案2
apt-get 有一个-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 a unauthenticated
package or removing an essential package occurs then apt-get will
abort. Configuration Item: APT::Get::Assume-Yes.
或者,也可以换一种方式--force-yes
:
Force yes; this is a dangerous option that will cause apt to
continue without prompting if it is doing something potentially
harmful. It should not be used except in very special situations.
Using force-yes can potentially destroy your system! Configuration
Item: APT::Get::force-yes
http://manpages.ubuntu.com/manpages/utopic/man8/apt-get.8.html