Bash, Zsh and Fish: The awesomeness of Linux Shells

My wife the other day saw a black screen overlayed with white text on her computer and she freaked out. She instantly thought that there was something wrong with her computer. Of course, I just looked at her with a smiley face.

The terminal is nothing more than a blank page to a writer. It's very intimidating because it requires you to do something, anything really else it'll keep starring at you forever.

Originally computers were operated via the command line which made them terribly difficult to use. They were reserved for the nerds because you had to have an idea of what do to with it. Then Graphical User Interfaces(GUIs) arrived thanks to some research from Xerox park and then the rest is history.

But the command-line is still a very powerful tool for advanced users. The Unix/Linux commandline or terminal or shell is the most powerful each appealing to the curious, adventurous and the kool kids. They include; bash, ksh, zsh, tcsh, fish and others. However, I have particularly used bash, zsh and fish shells.

Bash

GNU Bash aka the Bourne Again Shell, is the most common Linux shell out there. In fact it comes as the default shell for most Linux distros.

bash-shell

Bash comes pre-installed with tone of powerful features that include
Looping Constructs, Conditional Constructs, Shell Functions, Bourne Shell Builtins, Bourne Shell Variables, Brace Expansion, Tilde Expansion, Aliases to mention just a few. With these you can write cool bash scripts that can help you automate certain functions such as backups, application installations and deployments, text search and editing among other things.

For example here's a one-line script that demos use of for loop and if statement;

$ for i in $(ls -l *.pdf); do if [ "$i" == "SlSupportPolicy.pdf" ]; then echo "got file $i"; fi; done; 

got file SlSupportPolicy.pdf  

Bash is really awesome.

Zsh

Originating in the early 90s, Zsh is yet another great shell that's not any different from Bash.

But what makes Zsh too awesome is when you combine it with oh-my-zsh. Oh-my-zsh is community-driven framework for managing zsh configuration. It includes 200+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, php, python, etc), over 140 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.

zsh-magic So Zsh+oh-my-zsh framework will give you auto-completion, tab completion, several cool themes, programming language integration and like bash is Posix compliant.

Installation

#install zsh
sudo apt-get update  
sudo apt-get install zsh

#install oh-my-zsh with auto-suggest, syntax-highlighting plugins

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

git clone git://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

vi ~/.zshrc  
ZSH_THEME="kennethreitz"  
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

Fish

Fish is simply my favorite shell for the following reasons;

  • Syntax highlighting for commands, comments.
  • Auto suggestion based on your terminal history
  • Auto competition generated by parsing man pages which makes it super smart.
  • Optional Web-based configuration although you can also edit ~/.config/fish/config.fish directly using Vim or any other text editor.
  • And just works out of the box. Not much configuration and tweaking is required. Fish shell The bummer with fish is that it's not entirely Posix-compliant. So sometimes my one-liner bash commands just brake. For instance && operator doesn't always work as expected.

installation

sudo apt-get update  
sudo apt-get install fish  
How to change user's shell

Changing a user's shell is very easy. You can either you use chsh command like below which changes dave's default shell to zsh;
sudo chsh -s /bin/zsh dave
Or you can edit /etc/passwd file and manually edit the user's shell from there.

Because of several options out there, sometimes it's hard to make a choice. I would recommend that if you are developer, then you should go with Zsh+oh-my-zsh combo. Sys admin can stick to the good old bash and Devops guys might definitely find fish a plausible alternative. Personally I tend to oscillate between fish and zsh depending on what am doing.

Image: calacademy.org

David Okwii

David Okwii is a Ugandan-based Technology writer and System's Engineer.

Kampala Uganda http://www.davidokwii.com

Subscribe to oquidave@geek:~ #

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!