running an installation command in bash: “n” followed by “Y” without any manual intervention

StackOverflow https://stackoverflow.com/questions/10308533

  •  03-06-2021
  •  | 
  •  

Question

So on a fresh instance of arch linux, I want to be able to install tzdata from the get-go.

To do so manually, I do this:-

[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

As can be seen, I have to first key in n, followed by Y.

How do I run run this in one single line of bash without needing to key in n and Y?

yes n | pacman -S tzdata

gets me pass the first prompt. But I get stuck on the second prompt (obviously).

Was it helpful?

Solution

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

OTHER TIPS

If you want to send multiple inputs to a program like this, one way is to have multiple echo commands in a subshell:

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

Side note: Pacman really should be updated first if there's an update. Then you could just use --noconfirm like the other answer says.

What about

echo -e 'n\nY' | pacman -S tzdata
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top