How to automatically install a program bash suggests I install?

If you set the environment variable COMMAND_NOT_FOUND_INSTALL_PROMPT to 1, like

export COMMAND_NOT_FOUND_INSTALL_PROMPT=1

you will be ask if you want to install the package:

me@myhost:~$ tiger
The program 'tiger' is currently not installed. You can install it by typing:
sudo apt-get install tiger
Do you want to install it? (N/y)

If you answer y it will run

sudo apt-get install tiger

See How do I set environment variables? for how to set environment variables.