12

I am working on a simple bash script that configures new servers how I want them. It's nothing special but it will hopefully save me quite a lot of time in the future.

How do I prevent prompts like this:

  You are about to add the following PPA to your system:
    Stable version of nginx.
    More info: https://launchpad.net/~nginx/+archive/stable
  Press [ENTER] to continue or ctrl-c to cancel adding it

When running commands like this from a script:

  sudo add-apt-repository ppa:nginx/stable 
  sudo apt-get update
  sudo apt-get -y install nginx

Is there an auto accept flag that I can set or something like that?

25

add-apt-repository has a -y flag you can use, which should do the trick.

Though I really want to suggest that you look at configuration management systems like puppet or chef to configure servers. They'll save you a lot of time!

| improve this answer | |
  • Perfect, thank you. I am going to look into both and see if I can get my head around them. Thanks again! – dannymcc Feb 3 '13 at 11:51
  • -y is for bypass confirmation "yes/no", it is not for "Press [ENTER] to continue or ctrl-c to cancel adding it" – Trong Tran Jul 8 at 4:01
15

It's probably worth noting that this is what yes was written for. It by default prints a y repeatedly, but yes <string> will just repeat "string" instead.

If you're presented with a bunch of responses like:

Press [ENTER] to continue or ctrl-c to cancel adding it

You can do something like:

yes '' | sudo add-apt-repository ppa:nginx/stable

To automatically put an enter at every prompt. Given that apt-add-repository has a -y option, you should use that, but if you ever encounter a script that doesn't have that option, you can use yes.

| improve this answer | |
  • This is correct answer. Thanks @Erik – Trong Tran Jul 8 at 4:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.