godzilla
godzilla

Reputation: 3125

run bash script without input

I have written a bash script which installs a number of packages, however for each consecutive package installation i am promoted with the following message:

After this operation, 1,006 kB of additional disk space will be used.  
Do you want to continue [Y/n]? 

Is there a way of setting the default to Y so no user input is required? My script is expected to run at night without any intervention

thanks in advance

Upvotes: 12

Views: 6118

Answers (2)

Misch
Misch

Reputation: 10840

I think that message looks like you are using apt-get.

In that case you can use the flag --assume-yes or shorter: -y, which should automatically answer yes to that question without prompting the user

Upvotes: 4

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38032

Two methods come to mind. The first (and better option) is to use the options in your package manager. For example:

apt-get install -y [YOUR_PACKAGE]

if you use apt (type apt-get install --help for more help there).

The second is more of a quick-'n-dirty one...use a pipe after yes:

yes | apt-get install [YOUR_PACKAGE]

which always brings a smile to my face :p

The latter option also answers yes to ALL other questions, which can be handy (errors etc.) but can be risky (which is the reason those questions are there in the first place!)

Upvotes: 16

Related Questions