What is Bash shell, and know its importance in Linux

If you have ever seen any movie or series with a “hacker” character (a genuinely good example would be Mr. Robot), you have seen this scene. There is a bunch of random text on the screen, the hacker puts in some command, and the screen pours out more information. So what’s that all about? Why are there no icons or anything graphical? Well, I am here with an answer.

What is being shown in a scene like this is a Command Line Interface (CLI). The CLI of any operating system makes it possible for mere mortals like us to interact with the complex systems of our machines. We enter commands in the form that we understand them. Next, they are sent to the shell, the software that makes sense of the commands, variables, and names that we put in. Finally, the command is executed, and we are provided with the results.

In simple words, a shell provides an interface to the operating system.

This article will talk about one particular shell, namely Bash. Bash is the shell that is used most widely among the Linux distributions. It is the default login shell for most Linux distributions. Therefore, when you see any Linux terminal commands anywhere, they mostly refer to the Bash shell. That said, let us get into its history.

History of Bash

First came the Thompson shell

The Thompson shell came with the first release of Unix in 1971. Ken Thompson wrote it, and it was only a simple command interpreter. The shell was very compartmentalized. The feature that helps the shell identify filenames using patterns was separate from the shell in a script called glob. Even the if command to evaluate conditional statements differed from the main shell. As a result, the shell came in below 900 lines of C code.

But the shell included many features still found in modern shells. The method of redirecting information (example: | or >) flow and sequencing multiple commands in a single line (example: semicolon[;] or &&) have still survived.

The main shortcoming of the Thompson shell was the lack of scripting. You could sit and type in commands all day long, but you couldn’t write a script that could run a sequence of commands with the execution of a single file.

Next came the Bourne shell

The Bourne shell was released to accompany Unix 7. Stephen Bourne developed it and introduced several improvements over the older Thompson shell. The Bourne shell most notably introduced variables, control flows, and loops. It provided the ability to create scripts as well. The only lack that the Bourne shell had was the inability to develop functions.

And thus the shell was Bourne again

Finally, as a part of the GNU Project (the GNU project was created by Richard Stallman to provide quality software, like Unix, for free for everyone to use), the Bourne shell was recreated as the Bourne-Again Shell or our dear Bash. It was developed finally by Brain Fox, who made the brilliant choice to name it after a pun and not himself.

Since its creation in 1988, Bash has been adapted to most Linux distributions. Apple has even adopted it in their Mac OS Catalina and adapted it to Microsoft Windows. Bash has been in development, being constantly improved upon, and is used continuously by users worldwide.

Why is Bash still so relevant?

Bash has survived the bashing of time because of how it got intricately intertwined with Linux at its early age, not to mention that it is simply compelling. Linux gradually spread all over the world. We all know the story. Most of the web servers run on Linux. Android is based on Linux, and Linux is the backbone of IoT. As Linux spread around, so did Bash. Especially talking about servers or IoT, most of the time, all developers get is a command-line interface to the system, not the beautiful GUIs that we are used to on Linux desktops. Even desktop users like to utilize the power of Bash. Most graphical applications developed for the Linux desktop use Bash commands to get their information. So as you can see, it is no surprise that Bash is so important for Linux.

What can you use Bash for?

Think of it like this: the desktop’s graphical interface is built on top of the command-line interface that existed before it. So unless it has something to do with graphics, like images or videos, you can do anything with Bash. Navigating your system; copying, moving, editing, or deleting files; managing system processes; managing applications installed on your system; connecting to remote systems; managing permissions and ownership; you name it, it probably exists.

How can you use Bash?

Using a Linux-based desktop all starts with opening up the terminal application. Ctrl+Alt+T should work on most systems, but search your application menu if it doesn’t.

Let’s start with some basics:

Listing Files

Enter this command in your terminal, and you should see the list of files in your home directory:

ls

Now let’s add some more details:

ls -la
Listing Files
Listing Files

The result of this command will show you the names of the files, but it will also show up hidden files in the directory, the permissions of the file, the owner of the file, the size, and some more information.

Moving to another directory

Moving to another directory is easy. For example, we are going to move to the Downloads directory here:

cd Downloads/

Now enter the listing command to see that you have moved to the Downloads directory.

Changing Directory
Changing Directory

Creating files

To create a file, all you need is the name and extension of that file. For example:

touch try.py
Creating a File
Creating a File

Here, I created a Python file with the name try. You can do that with any filename and any extension.

Deleting files

Deleting files can be done with the rm command:

rm try.py
Deleting a File
Deleting a File

Check the system monitor

There is a primary CLI-based system monitor that comes with Linux. It can be launched with this command:

top
The Top System Monitor
The Top System Monitor

Press Q to exit the system monitor.

For more information about these basic commands, check our article about 20 Linux commands that beginners should know.

Bash scripting

Sometimes, a situation calls for a whole script. For example, you have a situation where you need to enter a string of commands, one after another. And this situation presents itself very often. It is not efficient to enter these commands every single time, again and again. So instead, create a script in which you put in those commands in the order you want, and when you need to enter those commands, just executing that file would be enough.

In other words, Bash scripting is like a full-fledged programming language. You can create variables, functions, conditional statements, and everything you would do in any programming language like Python.

Conclusion

Bash is one of the foundational pillars of the Linux ecosystem. Its usability, power, control, and speed have defied the test of time for more than 30 years now. If you want to use Linux as a simple desktop for basic tasks, you can get by without the knowledge of Bash, but if you’re going to become an advanced user and gain more power on the Linux front, Bash is an inescapable skill to learn. We hope this article was helpful. Cheers!

AD

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

SPONSOR AD
22,858FansLike
454FollowersFollow
16SubscribersSubscribe

More Articles Like This