قالب وردپرس درنا توس
Home / Tips and Tricks / What is the Bash shell and why is it so important to Linux?

What is the Bash shell and why is it so important to Linux?

An illustration of a laptop with a terminal with lines of text.
fatmawati achmad zaenuri / Shutterstock.com

The Bash scale is over 30 years old and is still going strong. What does it do, where does it come from and why is it still the most common shell on Linux systems?

What is a shell?

When you open a terminal window and type commands, you should take something you typed, figure out what you intended to do, and perform the tasks you asked for. The software that does this is the shell. A shell is a command interpreter. It scans what you have typed and chooses the commands, directory names, file names and program names so that it can figure out what you are trying to achieve.

People often use the expressions “terminal windows”

;, “command line”, and “shell” interchangeably, but they are three different things. A terminal window is a software representation of a physical teletype terminal. It gives you a connection to the computer. To do anything useful, you need to be able to type instructions on a command line. The command line is provided by the shell and the terminal window gives you access to the shell.

Shells also allow you to split a collection of commands into a text file called a script. All of the commands in the script are executed for you every time you run the script. Scripts provide efficiency, repeatability and convenience.

The first Unix scale was called the Thompson scale sh. It was written by Ken Thompson, who is arguably the most important member of Unix’s original founders at Bell Labs. The Thompson shell was used as the standard Unix shell through Unix version 6. It was replaced in 1979 by the Bourne shell in version 7 of Unix.

RELATED: What is Unix and why is it important?

The Bourne Shell

Written by Stephen Bourne, the Bourne shell was an improved replacement for the Thompson shell. It was even started with the same command as the Thompson shell, sh, to maintain backward compatibility with existing scripts. Backward compatibility was important, but new features were added that provided a lot of functionality that we still use today.

The Bourne shell was an interactive shell and scripting language. It supported the execution of foreground and background tasks and basic task control. Pipes and redirection have been added, along with improvements in loop handling.

The shell now includes some built-in commands, meaning it didn’t have to pass everything to external utilities, making it more efficient. The Bourne shell even supported “here documents”, an elegant way to automate the submission of data to commands.

The Bourne shell raised the bar and became the new standard.

RELATED: How to Use “Here Documents” in Bash on Linux

The Birth of Bash

In 1984, when the GNU project announced its intention to create a free Unix clone – written from scratch and with a new, permitted license – the team needed a shell. When a volunteer who had been working on a shell for the GNU project repeatedly failed to deliver, Brian Fox was tasked with writing a clone of the Bourne shell.

It was called the Bourne Again Shell of Bash. This was partly a tribute to Stephen Bourne and partly a play on words for its sake. After its release in 1989, Chet Ramey contributed some bug fixes to Bash. He eventually became a co-maintainer of the Bash scale. Today he is still the maintainer of the Bash project.

Linus Torvalds, the creator of the Linux kernel, has said that the first two programs he ran on his new kernel in 1991 were Bash and gcc, The GNU compiler. Linking the GNU utilities with the Linux kernel was beneficial for both parties. The GNU operating system needed a kernel, and the Linux kernel needed everything else that makes up a Unix clone.

Since Bash is the default GNU shell, it became the default shell on all GNU / Linux distributions. Linux thrived to the point that it now supports an astonishing amount of the modern world. The Bash shell also surfed that wave of success.

Bash incorporates and enhances the Bourne shell’s feature set, but it has also taken inspiration from other shells such as the C shell (csh) and the KornShell (ksh). The extension of the tilde ‘~Until the value in the $HOME environment variable comes from the C shell and the fc command that calls the default editor for commands in the command history comes from the KornShell.

Bash introduced configuration files such as the “.bashrc” and “.bash_profile” files. Command line editing on Bash far exceeded the capabilities of previous shells. The manipulation of previously executed commands in the command history was an improved version of the C-shells “bang history” feature. Brace extension was a feature missing from the Bourne shell implemented in Bash as a superset of the functionality in the C shell. Arrays have been improved by removing their size limitations. Parameter extension in the command prompt allows users to customize their Bash prompt.

The Bash shell is intended to comply with the POSIX P1003.2 / ISO 9945.2 Shell and Utilities standard.

RELATED: Has Linux Killed Commercial Unix?

Why Bash Still Matters

An Apple MacBook Pro partially closed and glowing in the dark.
Omar Tursic / Shutterstock.com

Bash couldn’t have lasted as long – over 30 years – as the standard Linux shell had it not been working. Due to its long lifespan and huge user base, Bash is mature and very stable. Many alternative shells are available, from veterans such as the C shell and the KornShell to newer shells such as the Z shell (zsh) and the Friendly Interactive Shell (fish). Both the Z shell and the Fish shell have some features that Bash doesn’t do as well as arguably better ways to accomplish some of the same things that Bash does. So why is Bash still the dominant scale?

Of all the Linux machines I’ve ever had to manage, I can’t remember one that didn’t have a Bash shell. Unix machines, yes, but Linux boxes, no. It’s Bash every time. This familiarity allows you to get started quickly and be effective immediately. You already know Bash, so there is no learning curve. You are not paralyzed by small differences in syntax that make you go around in circles trying to figure out why something is not working. Time spent figuring out what the spell should be this shell is dead time, so it is in the customer’s best interest to use a known and commonly used shell.

Using a shell that is – or tries to be – POSIX compliant is important for many Linux distributions, but what is more important is backward compatibility. Obviously, it is unattractive to make changes that could break existing scripts. Attractive or not, sometimes you just have to bite the bullet. On September 3, 1967, Sweden switched from driving on the left to driving on the right. At 4:50 am all traffic had to stop, slowly move to the other side of the road and stop again. At five o’clock in the morning traffic could continue again, everyone was now on the right.

Will Bash Ever Be Replaced?

What seems unimaginable now can actually happen later. Unless we want to stick to the belief that we’ll all be using Bash until doomsday, the truth is likely that Bash will one day be replaced as the default Linux shell – whether it’s still the GNU default shell or not . Or maybe it will be Bash, but improved far beyond the scale we use today. But whatever replaces the current Bash will either have to be fully (or nearly) backward compatible or worth the upheaval, whatever the perks may be.

This is not without precedent. Since version 10.15 of macOS, Apple has dropped Bash and adopted the Z shell as the default shell. Apple has problems with the GNU General Public License (GPL) v.3. Unfortunately, that’s the license Bash uses. The last version of Bash released under GPL v.2 was version 3.2 of 2007. The current version is 5.1. Apple was almost a year and a half behind. The only way Apple could add an up-to-date shell without going to GPL v.3 was to move to a different shell. For Apple, that was worth the change. (However, you can still switch back to Bash on macOS if you prefer that!)

There is a big difference between an advanced user’s workstation and a corporate Linux server that you need to manage remotely over an SSH connection. Of the nearly 1.5 million servers hosted by Amazon EC2, more than 93% run on Linux. Almost 75% of the web servers run on Linux. Organizations such as Red Hat, Amazon and Google use Linux internally.

It’s hard to imagine what benefits a new scale could bring to justify that kind of global turmoil. Hence, Bash is cemented in place.

Even Microsoft now offers a way to run a Linux-based Bash shell on Windows 10!

Source link