Bash Shell Scripting

An introduction to Bash Shell Scripting

Welcome to the Land of Linux's Basic Shell Scripting Tutorial

Within this tutorial we aim to provide you with an understanding of the BASH shell and its uses for scripting. This tutorial is aimed ideally at users who have a basic experience of the UNIX/Linux command line. Ideally you will need to be familiar with general navigation commands such as "cd" and familiar basic commands such as "cp", "mv", "mkdir", "find", "grep" etc..

If you are not familiar with these basic commands do not worry, you can quickly learn about these from our Linux Basic Fundamentals Tutorial.

The tutorial is broken down into various sections which can be found here: Bash Tutorial

BASH - Bourne Again Shell

Bash as you may have gathered is the name given to the Bourne Again Shell, a replacement for the older Bourne Shell. Bash is one of the most popular shells available to Unix and Linux systems. If you have logged into a GNU/Linux system you probably have already encountered the Bash shell. Bash is generally the default shell that is distributed with most GNU/Linux operating systems. Bash is basically a command processor that allows users to issue commands that carry out various actions. These commands can be combined within a file and are known as scripts. If you would like to verify that you are using the Bash shell, then this can be achieved by simply issuing the command "echo $SHELL" from the command line. The syntax of these and many more commands will be explained throughout this tutorial:

john@john-desktop:~$ echo $SHELL

What is a Shell?

A shell is simply a program that takes commands you have issued from a keyboard and passes them to the Operating System for processing. The shell is basically an interface to your system. As we mentioned earlier, Bash stands for Bourne Again Shell which is an enhanced version of the Bourne Shell program 'sh' which was created by Stephen Bourne. Do all Unix and Linux systems use Bash? The answer to this is simply no, many of the systems will use Bash, however, there are many different shells available to most systems. Another popular shell that is widely used on many "Unix" systems today is the "Korn Shell" by David Korn. Although we are going to concentrate on Bash scripting, the basic fundamentals should be very similar.

Through out this tutorial I will be using Ubuntu 12.04 LTS in conjunction with the Bash shell. To see which shells are supported, you can issue the following command "cat /etc/shells" from the command line:

john@john-desktop:~$ cat /etc/shells
# /etc/shells: valid login shells