Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run bash script without input

Tags:

bash

shell

unix

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

like image 949
godzilla Avatar asked Jul 06 '12 15:07

godzilla


2 Answers

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!)

like image 121
Rody Oldenhuis Avatar answered Oct 19 '22 07:10

Rody Oldenhuis


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

like image 33
Misch Avatar answered Oct 19 '22 06:10

Misch