Remove User interaction from apt-get when installing/removing things in a script

I have a script which removes libreoffice and installs openoffice instead, how can I get apt-get to stop requiring the user to confirm this operation? I only want this to happen in the script so what switches should I use? I also want to reduce the output so it doesn't clog up the console.


You need to use apt-get --yes. Quoting from the man page (man apt-get):

-y, --yes, --assume-yes

Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactively. If an undesirable situation, such as changing a held package, trying to install a unauthenticated package or removing an essential package occurs then apt-get will abort. Configuration Item: APT::Get::Assume-Yes.

For example:

apt-get install --yes gedit

To reduce the output you can redirect it to /dev/null (only errors will be shown):

apt-get install --yes gedit > /dev/null

To make it produce zero output (not even print errors):

apt-get install --yes gedit &> /dev/null

Then, if something goes wrong, you will be able to find information in /var/log/apt.