The Linux Bash is also known as 'Bourne-again Shell.' It is a command language interpreter for the Linux based system. It is a replacement of Bourne shell (sh). It was developed under the GNU Project and written by Brian Fox. Nowadays, Bash is the default user shell of most of the Linux distributions.
The Linux/Unix shell allows us to interact with the Linux system through the commands. It let us invoke an executable file to create a running process. Moreover, it also allows us to interact with the Linux file system. It is designed in such a way that we can perform all the Linux operations through Bash.
The Bash is a command language interpreter as well as a programming language. It supports variables, functions, and flow control, like other programming languages. It can also read and execute the commands from a file, which is called a shell script.
It offers various functional improvements over Bourne Shell (sh) for both interactive and programming use. Although many sh scripts can be run by Bash without any change. The Bash contains the following improvements over sh:
How to download Bash
People often get confused between bash, shell, and shell script. Let's walk through shell and scripting to clear a picture of bash, shell, and scripting.
What is Shell
If we are a new Linux user, and we open the terminal, it is assumed that we are well confused as to what to do with it. Here the Shell comes in the role.
The terminal contains the shell; it allows us to execute the commands to interact with the system. We can perform various operations such as store and retrieve data, process information, and various other simple as well as complex tasks.
To open the terminal, press CTRL+ALT+T keys. Perform some basic operations such as date, cal, ls, and pwd to take a tour with it.
Consider the below image:
As we can see from the above image, the shell allows us to interact with the Linux system. When we have executed the date and cal command, the shell interacts with the system and retrieves data.
What is Scripting
Suppose we are required to execute some basic commands every day, for example above four commands. Linux supports a feature called scripting that allows us to execute more than one task at once. So, it is good to define a script rather than performing repetitive tasks.
To understand how to use Linux script, let's define a script in a combination of some tasks. To define a script, create a file with a .sh extension. We are using the VI text editor. However, any text editor can be used to define a script. Consider below command:
The above command will open the vi editor in normal mode. Switch it to insert mode by pressing ESC, and after that enter 'i' keys, enter your desired tasks. Every task should be defined in a new line. Consider the below tasks:
After entering the tasks, press ESC and :wq! Keys to save and exit from the editor.
Now, make the created file as executable, use the chmod command with +x option as follows:
We have created our first script. To execute the shell script, execute the file name by predefining './ ' with the file name. Consider the below command:
Consider the below output:
As we can see from the above output, by using the shell, we can automate the tasks. We can use this whenever we need it. It can be used repeatedly any number of times.
Features of Bash
All the built-in command of the sh shell is available in Bash; moreover, it facilitates us with many other features. Some key features of Bash are as follows: