Home etc Blogs A List of Linux Shells to Choose From

A List of Linux Shells to Choose From

0
3979

The use of command line interfaces in this era of multimedia and advanced graphical user interfaces might seem like an unnecessary mental exercise or showing off. But often, that is not the case. Here is a list of a few popular Linux shells that users can choose from.

I am sure all of you have used the terminal emulator (command line interface or CLI) of your operating system, be it Microsoft Windows PowerShell, Linux Shell, or the macOS Terminal. To a casual observer, the use of command line interfaces may look like someone unnecessarily showing off their skills. But trust me, this is not the case. I know a few people who depend solely on the CLI to carry out their work, to the extent that they practically don’t use the mouse at all. And these are power users of Linux Shell who are among the best in their trade. Having met such super-efficient professionals, I believe the art of using the Linux shell is yet another skill we need to master to advance our careers.

But instead of introducing the basics of shell scripting, I will instead feature a few popular Linux shells so that readers have a list to choose from. A shell called Bash is the default login and scripting shell for most Linux distributions and many of us are addicted to it, without even considering the competition. In fact, there are a number of other shells that one can choose from. In this article, we will be discussing Bash and a few other shells that can be used instead of it. Some of these alternative shells include the Bourne shell, the C shell, KornShell, etc. The other important question that will be addressed is whether there are any key differences between these different Linux shells. In short, should an average user migrate from one shell to another under any particular circumstance?

The Bourne shell
Though the most widely used shell is Bash, let’s begin our discussion with the Bourne shell, which is one of the oldest among the list we are going to discuss. The Bourne shell was developed by Stephen Bourne at Bell Labs. It was first released in 1979 as part of the UNIX operating system and in most Linux OSs, the Bourne shell is pre-installed. The command ‘echo $0’ prints the current shell. Figure 1 shows that the default shell in my Ubuntu operating system is Bash. The Bourne shell can be invoked with the command ‘sh’ on the terminal. We can see that the second execution of the command ‘echo $0’ shows that the current shell is now the Bourne shell.

Figure 1 also shows the output of the commands ‘pwd’ and ‘date’ in the Bourne shell. From Figure 1 we can also see that the command ‘exit’ will take you back to the default shell (Bash). An important question is regarding the License under which the Bourne shell is released. Here there is some confusion. Solaris distributes a version of the Bourne shell under the Common Development and Distribution License (CDDL) and FreeBSD distributes a version of the Bourne shell under the BSD license. Though both are free and open source licenses, the confusion remains as to under which license Bourne shell is released at present. Since Bash is well maintained and supported, it is not known if people actually use the Bourne shell as their primary shell of choice.

Figure 1: Using the Bourne shell in Linux

GNU Bash
Now let us discuss the default shell for most of the distributions of Linux called GNU Bash. Even though the shell is popularly known as Bash, it was originally named as Bourne-again shell, a pun on the name of the Bourne shell. This is yet another example for funny names being given to GNU software that replaced original UNIX software. Other such examples include the parser generator Bison (replacing Yacc), the spell checker Aspell (in place of Ispell in UNIX) and the recursive acronym of GNU (‘GNU’s not UNIX!’) itself. Bash was developed by Brian Fox, and is compliant with the POSIX standard. It is free and open source software licensed under the GNU General Public License. We have already seen that Bash is the default shell in the Ubuntu operating system. In fact, Bash is so popular, it is the default shell in Linux distributions like Ubuntu, Fedora, CentOS, openSUSE, etc. But as seen by us already, it is very easy to switch from one shell to another. Figure 2 shows some basic commands like ‘pwd’ and ‘date’ executed on the Bash terminal.

Figure 2: Using Bash in Linux

KornShell
Now let us work with another popular shell called KornShell, which was developed by David Korn at Bell Labs. It was originally proprietary software but now is free and open source software under the Eclipse Public License. Because of its early history as proprietary software, there are many open source alternatives to Kornshell like mksh, pdksh, etc. Notice that, unlike the Bourne shell and Bash, KornShell is not pre-installed in Ubuntu. But the installation took just one command ‘sudo apt install ksh’ in Ubuntu and was very smooth. I am sure the installation of KornShell on other Linux distributions will be equally simple. KornShell is usually invoked with the command ksh. Figure 3 shows some basic commands like ‘pwd’ and ‘date’ executed on the KornShell terminal. From Figure 3, we can also see that with the execution of the command ‘exit’ the default shell Bash is ready again for operation.

Figure 3: Using KornShell in Linux

The Z shell
Now let us discuss the Z shell, which was developed by Paul Falstad. It is free software released under the MIT License. Till macOS Mojave (Apple’s desktop operating system for Macintosh computers) the default shell was Bash, but in the current operating system called macOS Catalina, the Z shell has been chosen as the default option. I believe this is a notable achievement and justifies the inclusion of Z shell in this list. Notice that, like KornShell, Z shell is also not pre-installed in Ubuntu. But once again, the installation took just one command: ‘sudo apt install zsh’. This time also the installation was very smooth. The Z shell is usually invoked with the command ‘zsh’. Figure 4 shows the execution of the commands ‘echo $0’, ‘pwd’, and ‘exit’ on the Z shell terminal.

Figure 4: Using the Z shell in Linux

The C shell
The popular C shell was developed by Bill Joy and is free software released under the BSD license. Notice that the C shell is also not pre-installed in Ubuntu. But just like the installation of KornShell and the Z shell, installing the C shell also required just one command: ‘sudo apt install csh’. This installation too was very smooth. The C shell is usually invoked with the command csh. This is a shell that is somewhat different from the four discussed earlier.
From Figure 5, we can see that the command ‘echo $0’ to print the name of the current shell doesn’t work with the C shell. So the command ‘ps -p $$’ is used to print the name of the current shell. Notice that this is the first time a shell has displayed behaviour that is different from the others. Figure 5 also shows some basic commands like ‘pwd’ and ‘date’ executed on the C shell terminal. From Figure 5 we can see that on executing the command ‘exit’, the default shell Bash is ready again for operation. The C shell has an advanced version called tcsh, which can be invoked with the command ‘tcsh’. But you need to install tcsh also with the command ‘sudo apt install tcsh’. Figure 5 also shows the tcsh shell invoked and the command ‘pwd’ executed on it. From the figure, we can see that the commands ‘echo $0’ and ‘exit’ also work as expected.

fish
Now let us discuss one more shell called fish that can be used in Linux. Of course, I could have kept on extending this list by installing and testing obscure shells with no distinctive features. All the other shells were chosen for historic reasons or current impact. I might have missed a few important ones – I don’t know. But fish was included in this list for a third reason. While researching for this article, I accidentally stumbled upon the official website of the fish shell. The site claims that the shell is ready for the 90s! The tone made me think that the shell had been developed in the late 80s and the team was being futuristic! Actually, that was not the case. The team behind fish was being very humble. Though it was first released in the mid-2000s, fish claimed to be behind the times and only ready for the 90s! This fun way of advertising the features of this shell caught my attention. fish is free and open source software released under the GNU General Public License.

Figure 5: Using the C shell and tcsh shell in Linux

With claimed features like ‘Auto suggestions’, ‘Glorious VGA Color’, ‘Web based configuration’, etc, the fish shell looks promising. So, I felt like including fish in this list of Linux shells. Notice that the fish shell is also not pre-installed in Ubuntu. But it too can be installed very easily. Figure 6 shows one important feature of the fish shell, ‘Auto suggestions’. It can be seen from the figure that by just typing the letter ‘a’, the command ‘apt-get update’ gets offered as a suggestion.

Figure 6: Using the fish shell in Linux

Now let us compare these six shells a bit more. Since a shell is just an interface that allows the user to communicate with the underlying kernel of the operating system, while using basic Linux commands we can’t expect major differences because of the execution of the underlying Linux system calls. But one major area where the various shells could behave differently is in their shell script syntax. Let us consider the simple Bourne shell script called bshell.sh shown below, which checks whether the number entered through the keyboard is odd or even. Of course, this shell script called bshell.sh is very simple, but it is sufficient to test the syntax of the various shells we have discussed in this article.

echo “Enter a Number “
read num
rem=`expr $num % 2`
if [ $rem -eq 0 ]
then
echo “Even Number”
else
echo “Odd Number”
fi

Figure 7 shows the output of the shell script bshell.sh when executed by the following different shells — the Bourne shell, Bash, KornShell, mksh and the Z shell. From Figure 7, it is clear that they were all able to execute the shell script correctly without any errors. So we can conclude that the Bourne shell, Bash, KornShell, mksh and the Z shell have similar syntax. Of course, there could be minute differences between all of them. Figure 8 shows the execution of the shell script bshell.sh by the C shell, tcsh, and fish. From Figure 8, it is clear that all three of them failed to execute the script bshell.sh.

Figure 7: Successful execution of the script bshell.sh

Now let us consider the shell script shown below called cshell.sh. This script is written in C shell syntax and is equivalent to the script bshell.sh, which checks whether the number entered through the keyboard is odd or even.

echo “Enter a Number “
set num = $<
@ rem = $num % 2
if ($rem == 0) then
echo “Even Number”
else
echo “Odd Number”
endif

Figure 9 shows the output of the shell script cshell.sh when executed by the following two shells — the C shell and tcsh. From Figure 9, it is clear that the two shells were able to execute the shell script correctly without any errors. So, we can conclude that the C shell and tcsh have similar syntax (an obvious conclusion since tcsh is an upgraded version of the C shell). Notice that the C shell syntax has some similarity to the syntax of the C programming language. But this is not surprising because syntactic similarity with C was one of the design goals of the C shell. Figure 10 shows the execution of the shell script cshell.sh by the Bourne shell, Bash, KornShell, mksh, Z shell, and fish. From Figure 8, it is clear that all six of them failed to execute the script cshell.sh. Notice that the syntax of the fish shell script is different from all the others — but to what extent this is so, I don’t know. I believe exploring the features of this shell called fish is an article for another day. But I urge you to explore this shell further. Both the shell and its manual look very creative.

Figure 8: Failed execution of the script bshell.sh

Figure 9: Successful execution of the script cshell.sh

So, after our brief comparison of these Linux shells, it feels that for an average user of Linux, the differences in the behaviour of the shells may not be that visible. There are two reasons for this conclusion. First, whichever may be the shell used, the basic Linux commands are processed in the same way. Second, even though there are differences in the syntax of the shell scripts being used, these are not significant. Of course, there are differences between shells as far as features like string processing, remembering the command history, automatic command completion, automatic suggestions, and many more are concerned.

Figure 10: Failed execution of the script cshell.sh

I am sure ardent fans of a particular shell might have a lot of reasons for their choice, but to a typical Linux user who is comfortable with one particular shell, the idea of migrating to another may not be that advisable due to the not-so-flat learning curve and the unexpected minor differences that might lead to errors. So, I believe, the moral of the story is that shell scripting is an important skill but if you are already comfortable with a shell then you probably don’t have any reason to migrate to another.

At the same time, if you are an absolute beginner to Linux, then it might be a good idea to give some serious thought to the options before you choose your Linux shell, especially if you plan to use Linux seriously and not just dabble in it.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here