Use a opção -y
para apt-get
.
Na página man :
-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.
Então, para você, seria algo como sudo apt-get remove -y foo1 foo2 foo3
e sudo apt-get install -y foo foo1 foo2 foo3
.