Writing a simple bash install script

While  installing programs the next simple trick might come in handy: create a bash script and let the terminal interface do all the hard work automatically.

First you need to open an empty text file (with gedit, leafpad, kate or any other). After you have the text file in front of you then you can start typing the install commands. For example I used the following very basic install script to set up my Ubuntu box.

sudo apt-get install jwm pulseaudio pcmanfm evince xserver-xorg libreoffice gimp gnome-control-center pavucontrol gedit synaptic  xinit ufw network-manager-gnome gnome-terminal firefox vlc

Once I had typed in the commands above I saved my text file as something.sh . The sh suffix is very important as it tells Linux terminal that the file is actually a script that should be read as such.

If you are very sure that all the programs you want to install are found exactly as you typed them and you do not want to even do the “confirm installation” part you can modify the script by adding -y at the end of the install lines. The -y at the end makes the script confirm the line automatically without any user input

If you would want to fine tune your script further see below for some basic examples.

#This is a script. This line is a comment

#Comments are not read while the script is executed

sudo apt-get install jwm pulseaudio pcmanfm evince xserver-xorg libreoffice gimp gnome-control-center pavucontrol gedit synaptic  xinit ufw network-manager-gnome gnome-terminal firefox vlc  -y

echo “Congratulations your automatic install script has finished ! you will also see this line when you are done.”

#Getting a Gpl background(or something else) from online with wget.

wget https://www.techtimejourney.net/wp-content/uploads/2013/03/green.png

#Enable firewall

sudo ufw enable

To startup your script:make sure that your script has an sh ending. For example: test.sh .

Run your script inside terminal typing something as follows: sh test.sh

Note: If you are not using sudo you should run the script as root. If you run the script as a root the wget part might however put the background to your root home folder instead of user home folder.  Do remember that the above is just an example: if you replace apt-get with yum or pacman -S you might adapt the script for Fedora or Arch, for example.

Note: in some cases you might need to make the script you have created an executable one. Type: chmod +x something.sh in terminal if such a procedure is needed. To get more information about the terminal commands take a look at this  post: https://www.techtimejourney.net/?p=630