在bash中运行安装命令:“n”后跟“Y”,无需任何手动干预

时间:2012-04-25 02:19:31

标签: sh pacman

所以在一个新的arch linux实例上,我希望能够从一开始就安装tzdata

要手动执行此操作,请执行以下操作: -

[root@myarch ~]# pacman -S tzdata
:: The following packages should be upgraded first :
    pacman
:: Do you want to cancel the current operation
:: and upgrade these packages now? [Y/n] n

resolving dependencies...
looking for inter-conflicts...

Targets (1): tzdata-2012c-1

Total Download Size:    0.13 MB
Total Installed Size:   5.41 MB

Proceed with installation? [Y/n] Y

可以看出,我必须首先键入n,然后键入Y

如何在一行bash中运行此操作而无需键入nY

yes n | pacman -S tzdata

让我通过第一个提示。但是我很困惑第二次提示(显然)。

3 个答案:

答案 0 :(得分:2)

{ echo n ; yes ; } | pacman ...

答案 1 :(得分:1)

如果你想向这样的程序发送多个输入,一种方法是在子shell中有多个echo命令:

(echo n; echo y) | pacman -S tzdata

旁注:如果有更新,应该首先更新Pacman。然后你可以像其他答案一样使用--noconfirm

答案 2 :(得分:0)

怎么样?
echo -e 'n\nY' | pacman -S tzdata