Zsh vs Bash – Which one you should be using?
Z-shell (or Zsh) is an interactive Bourne-like shell and a powerful command-line tool for scripting language including shell scripting. It’s known for its abundance of interactive and customizable features. Zsh users often cite its many advantages and credit it for its efficiency and extensive customization.
Bash and zsh are both powerful shells and share many features. They also possess unique features that users may have different preferences for. This post will give an overview on the features of and comparison of bash vs zsh, how you can set both as your default shell, as well as some configuration recommendations.
Features of Zsh
- Auto completions of commands
- Auto change directories – Just type the directory name.
- Path expansions – /u/s/n will be expanded to /usr/share/nginx – If path is not unique, it will list the matching paths
- Environment variables expansion
- Approximated completions
- External modules support – ZSH includes many different plugin frameworks
The above features are just a few that will change your mind to shift to Zsh over Bash.
The official documentation of Zsh lists the following as innovative features over Bash.
- customise the environment in which you work, by using startup files,
- write your own commands to shorten tasks and store things in shell variables (`parameters’) so you don’t have to remember them,
- use zle to minimise the amount of typing you have to do — in zsh, you can even edit small files that way,
- pick the files you want to use for a particular command such as
lsusing zsh’s very sophisticated filename generation (known colloquially as `globbing’) system,
- tell the editor what sort of arguments you use with particular commands, so that you only need to type part of the name and it will complete the rest, using zsh’s unrivalled programmable completion system,
- use the extra add-ons (`modules’) supplied with the latest version of zsh to do other things you usually can’t do in a shell at all.
Features of Bash
Bourne-Again Shell’, bash is a freely-available enhancement of sh written by the GNU project.
- Directory manipulation using pushd, popd, and dirs commands.
- Job control, including the fg and bg commands and the ability to stop jobs with CTRL-Z.
- Brace expansion, for generating arbitrary strings.
- Tilde expansion, a shorthand way to refer to directories.
- Aliases, which allow you to define shorthand names for commands or command lines.
- Command history, which lets you recall previously entered commands.
- Dynamic loading of built-ins, plus the ability to write your own and load them into the running shell.
- Command-line editing, allowing you to use vi- or emacs-style editing commands on your command lines.
Which one you should be using? Zsh or Bash?
Spoiler alert – it all depends on the user. I’d call Zsh as Bash++ (like how Notepad++ is an extended and enhanced version of Notepad) but that doesn’t mean you should be jumping to Zsh straight away. If you’re acquainted with Bash, I’d say stick with it.
Leave a Reply