The shell is our entry point into working with systems and is undoubtedly one of the most powerful weapons in a sysadmins arsenal when it comes to configuration and administration. At Spearhead we firmly believe that the operating system is the most important building block of any system therefore the shell is equally important as it the gateway through which we interact with these systems.
Since we spend a considerable amount of time in front our computer screens working extensively with the shell, it is of upmost importance that it offers us good response times and high precision with its results. The default shell on most systems is bash (Bourne Again Shell) and is a fine piece of software. Bash offers many compelling features but while it may be the most widely used shell it is by no means the only shell around or even, dare I say it, the best.
I try to use the shell best suited for the job at hand and luckily ZSH is often the best choice. There are situations where ZSH is not available and I will fall back on whatever is present on that platform, most likely bash. There is an exception I apply however when writing scripts that need to be portable: I will try to write them in bash as I have a greater chance of having bash on remote systems where I am not in charge.
For my day to day work and those systems where I do have access over the default shell I emphatically prefer ZSH because is very similar to bash and most scripts will work without any modifications but there are differences that need to be understood.
ZSH is a power shell users dream with many features such as:
- last command scrolling
- tab navigation
- inline glob expansion
- right prompt (and left prompt)
- spelling correction
- multi-line editing
- Last command scrolling is a nifty feature that will save you time. For example say you want to scroll through files you edited with vim. You write vim and then using your up/down keys scroll through previous files you’ve edited.
- Tab navigation may take some time getting used to if you have not used it previously. It basically allows you to do tab completion but instead of autocompleting to the closest match it will expand a list of matches for you navigate using your arrow keys.
- Inline glob expansion allows the expansion of globs directly inline.
- Prompts are great. They offer important information and feedback as you work with shell. zsh offers support for some of the most advanced prompts as well as a right side prompt. This example shows just the time but you could do anything (battery level, wifi signal, output from commands, git info, etc.).
- Spelling correction is good for anyone who’s fingers are quicker than their brain :). Take for example recurring mistakes such as Grep instead of grep. ZSH can learn from your mistakes and autocorrect.
- Multi-line editing is one of my favourite features as I often do loops on the command line. Sometimes you need to modify something in the loop so having a multiline editor to see the entire loop but also edit directly is very helpful.
These are just a few of the reasons why zsh is my favourite shell. But there are other factors as well such as the great ecosystem of plugins and themes available to me. There is also Oh-My-ZSH which helps one get started very quickly with ZSH, themes and plugins without having to hand-craft them.
This article started off as a performance benchmark between bash and ZSH on my laptop. I had a vague feeling that bash upon returning from commands (system commands, loops, etc.) would lag a bit. Startup and shutdown of the login shell also felt sluggish so I embarked on some tests. Suffice it to say ZSH is faster, in some cases two times or more faster. There are quite a few benchmarks out there already so I won’t go into details here.
If you find this article interesting consider getting in touch with us if you are looking to optimise your IT operations or systems. We use dedication and careful attention to details to custom tailor systems, services and procedures for unique business requirements.
Many companies rely on our high performance attitude to get the job done and so can you!