自动按下 [Y] 的终端命令是什么?

dan*_*dan 8 terminal ubuntu

例如:如果我喜欢

sudo apt-get upgrade
Run Code Online (Sandbox Code Playgroud)

然后我可能会在安装更新之前收到 y/n 问题。自动接受它的参数是什么。

Jas*_*per 12

有两种方法可以做到这一点:

apt-get 具体:

$man 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. 
[...]
--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!
Run Code Online (Sandbox Code Playgroud)

一般:yes命令:

$man yes
yes - output a string repeatedly until killed [...]
DESCRIPTION
   Repeatedly output a line with all specified STRING(s), or 'y'.
Run Code Online (Sandbox Code Playgroud)

由于yesapt-get内部结构一无所知,因此它可能相当于--force-yes并因此危险。如果你仍然想这样做,你可以将输出通过管道yes传入apt-get

yes | apt-get update
Run Code Online (Sandbox Code Playgroud)