Auto confirm when running bash scripts?

Solution 1:

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!

Solution 2:

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.