How do I write a shell script to install a list of applications?

Solution 1:

I would assume the script would look something like this:

#!/bin/sh
apt-get update  # To get the latest package lists
apt-get install <package name> -y
#etc.

Just save that as something like install_my_apps.sh, change the file's properties to make it executable, and run it from the command line as root.

(Edit: The -y tells apt-get not to prompt you and just get on with installing)

Solution 2:

Well, according to your question the easiest script would be:

#!/bin/sh
LIST_OF_APPS="a b c d e"

aptitude update
aptitude install -y $LIST_OF_APPS

However you could also enter aptitude update && aptitude install -y a b c d e. So maybe your question is missing the crucial point here. If there are some further requirements it would be nice to explain them.

Solution 3:

Just create a list of apps in a file, example.list, and run

cat example.list | xargs sudo apt-get -y install

Solution 4:

I would opt for the following script: vim install

#!/bin/bash
apt-get update  # To get the latest package lists
apt-get install $1 -y

Then I should make the above script executable chmod +x install. Then to use it, I could type: ./install <package_name>. Example: ./install clang