0

I'm trying to automate a server setup using a shell script.

I need to install a few dependencies with apt-get and some require the user to input y before the install continues.

My question is how do I make sure the shell script automatically inserts y every time it sees something like Do you want to continue [Y/n]? ?

I've tried sudo apt-get install git << 'y' and 'y' | sudo apt-get install git but with no results.

What could I try next?

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
narzero
  • 2,199
  • 5
  • 40
  • 73

3 Answers3

3

Just use the -y or --yes flag as described in the apt-getman pages.

BTW there is even an option to --force-yes. So you got plenty of options at your hands.

three
  • 8,262
  • 3
  • 35
  • 39
1

yes | sudo apt-get install git

yes writes the word 'yes' to standard output over and over and over again. It can also be used to do the same for other words (ie. yes no | sudo apt-get... to repeat 'no' to stdin).

1

Use the yes command.

Like this:

yes | rm *.txt

This will remove any file, and the yes command means you don't have to answer the queries.

In your case,

yes | sudo apt-get install git

This is using the pipe functionaly to pipe "yes" responses into standard input.

Almo
  • 15,538
  • 13
  • 67
  • 95