Affiliate Disclosure: By buying the products we recommend, you help keep the lights on at MakeUseOf. Read more.
Happy using the bash shell in Linux? Or would you prefer to try out an alternative? There’s tsch, fish, KornShell, and Z Shell to choose from. But which of these Linux shells is best?
What Is a Shell?
Usually, when you write an application, it’s done in a high-level language that humans can understand. Examples of these are C#, Java, C++, etc. Believe it or not, your computer sees everything as 1s as 0s or, as commonly known, binary or machine code.
A compiler will then translate the high-level language into a binary file like an executable. This binary file is what you execute to launch said application. Now, this is a very high-level view of what happens, but just remember, your computer needs a translation layer between what you’re telling it to do and how it can understand that.
A shell is what’s known as an interpreter. Similarly to a compiler, an interpreter translates the human code into machine code. One of the differences is that an interpreter does this one statement at a time as opposed to a compiler which scans the entire program and translates it as a whole into machine code.
The shell, then, is an interface for you to interact with your operating system (OS). As you type commands into your shell, the shell is responsible for interpreting those commands and making the magic happen. Operations like copying files, piping, listing files are all within a shell’s remit. It is also responsible for remembering your command history for checking what went through your head at a time of possible inebriation.
To find out all the shells that are available on your system, open terminal and type:
To find out what shell you’re currently using type:
By a mile, the most popular shell amongst Linux users. It’s hard to even think about shells without the Bourne-Again SHell (bash) being a part of the equation. Many Linux distributions ship with bash as the default shell because bash is the default GNU shell. Released in 1989, it also boasts a few decades of healthy development behind it.
Bash’s predecessor is The Bourne Shell (sh) which is one of the original Unix shells. One attractive feature to sh programmers was that they could port their sh scripts directly to bash entirely unchanged. Bash also offers several enhancements to its predecessor like command completion and command history.
Bash is a perfectly respectable shell, and often online documentation will invariably assume you are using it. However, bash is not without its shortcomings — as anyone who has ever written a bash script that spans a few lines can attest to! It’s not that you can’t do something, it’s that it’s not always particularly elegant to read and write. Bash is probably here to stay for the near future at least. It boasts an extensive install base and brigades of casual and professional users alike, who are already accustomed to its usage, and quirks.
Commonly known as ksh, KornShell is an alternative shell that originated out of Bell Labs in the 1980s. Ksh began its life as proprietary software, being the de facto standard on commercial unices and therefore wasn’t available to Linux until 2000. There aren’t many differences between bash and ksh, but each has minor advantages over the other. Ksh, for example, has the cd old new command. If you were in the directory /Downloads/foo/bar/one/foobar and you needed to get to /Downloads/foo/bar/two/foobar you just need to run:
cd one two
Veterans of ksh will advocate it’s superiority by mentioning its scripting benefits. These include including having a better loop syntax, more natural ways to repeat commands, and the barely used, associative arrays. For basic input bash is quite similar to ksh for advanced scripting, however, this is sure to be a different experience. Another thing to be mindful of is requesting help for ksh online. This may involve waking a grizzled advanced user from his slumber to help you. Relative to bash, which will get you a flurry of answers almost immediately!
If you want to give ksh a try you can type:
sudo apt install ksh ksh
Tcsh can trace its roots back to the early days of Unix. It is essentially the C shell (csh) with programmable command-line completion, command-line editing, and a few other features. Tcsh is the default shell for BSD based systems like FreeBSD. The big selling point for tcsh is its scripting language, which should look very familiar to anyone who has programmed in C. Tcsh is a worthy candidate for learning if you find yourself primarily programming in C. This makes tcsh useful for prototyping small C programs without getting confused over things like which brackets you’re using. This problem tends to happen if you’re continually switching between C programming and shell scripting.
Tcsh’s scripting is adored by some and loathed by others. But it has other features as well, including adding arguments to aliases, and various defaults that might appeal to your preferences. One of its significant features includes the way auto-completion with <TAB> and history <TAB> completion work. After pulling up your history by typing history. Tcsh will display a numbered list of your previous commands, with a very convenient time stamp. You can run any command by typing !n replacing n with its corresponding number in the displayed history. History tab completion in tcsh works by typing:
This expands to the last command that started with the letter “a”. Comparatively, in bash, you would have to type !a:p to first see the command, followed by !! to execute it.
To give tcsh a try, type:
sudo apt install tcsh tcsh
Among all the seriousness of Linux, the team at fish have embedded a sense of humor in their project. On their website, the tongue-in-cheek title reads “Finally, a command line shell for the 90s” – fish (“friendly interactive shell”) was developed in 2005. Beyond the touted “Glorious VGA Color,” are some enhancements over other shells. Commands that have an invalid syntax will display as red, and correct syntax in blue. Additionally, there are lavish sets of tab completions like color-coded auto-complete suggestions which are based on your history.
Fish also boasts command completion based on the man pages on your machine. So if you’ve just installed a new program and need to get accustomed to its syntax, fish will grab the syntax from the man page and add it to your auto-complete suggestions. Neat! If you’d like to get more familiar with command line, fish can be a great place to start.
To sample what fish is about, type:
sudo apt install fish fish
5. Z Shell
Many would consider this to be leaving the best shell for last, which would be completely understandable. Zsh has similarities to bash and ksh and incorporates many of the features found in them as well as tcsh. Some useful features of zsh include a navigatable autocompletion list. Unlike bash which merely lists all available commands and gets you to type it manually. Globbing in zsh is inexplicably useful. Typing:
Automatically opens the file:
Spelling correction in zsh is far superior to that of bash. In a cd command bash can correct up to one character. Zsh, on the other hand, can be configured to autocorrect 10 spelling errors in one word. Zsh also nails command line histories. This is extremely useful for users who spend excessive amounts of time on the terminal. Zsh magically shares histories across terminals, making multi-terminal sessions a breeze.
Zsh can take a while to configure on first use if you don’t go with the default config. To give it a try, enter:
sudo apt install zsh zsh
Which Shell Is for Me?
The fact that these options are available is brilliant. They’re glimpses into the history of computing itself, where programmers decided they wanted to make things their own way, and eventually, set them free to the world.
The substantial differences between these shells can be found in the scripting syntax. Each shell has a particular set of nuances that separate them from each other. As it stands, bash dominates in terms of market share, which makes finding help much simpler. Bash is simply the best all-rounder, meeting the needs of all but the most advanced users.
Which shell do you currently use? Have you tried any shell other than bash? What do you love or hate about your current shell? Share your thoughts in the comments below!
Image Credit: spaxiax/Depositphotos