DEV Community

Cover image for Bash vs. Zsh: Key differences and when to use each
Megan Lee for LogRocket

Posted on • Originally published at blog.logrocket.com

1

Bash vs. Zsh: Key differences and when to use each

Written by Wisdom Ekpotu✏️

Both Bash and Zsh are important and powerful tools used to perform advanced activities that may ordinarily not be available with GUI tools. Bash is a lightweight, fast, and widely compatible command-line shell that prioritizes simplicity and portability, whereas Zsh is a more sophisticated shell that’s ideal for users that prefer customization and interactivity.

Introducing Bash and Zsh

Bourne Again Shell, commonly known as Bash, is a command line interface and scripting language) used by Unix-based operating systems to interact with terminal commands.

Z Shell, also known as Zsh, is also a Unix-based command line interpreter used to interact with terminal commands.

Some of the common uses of Bash and Zsh are:

  1. System administration — Both shells let users perform administrative activities like managing files, executing commands, and even creating automated scripts
  2. Development — Developers utilize these shells in debugging their scripts, installing packages, and even version control
  3. Unix default — On Unix-based systems, they are the default shells, with an option to access other shells from there

Let’s compare Bash vs. Zsh, discuss the differences, and explore how to use both.

Bash vs. Zsh: Feature comparison

Feature Bash Zsh
Default on Linux Yes No, except for Kali Linux
Default on MacOS No Yes, since MacOS Catalina
Default on Windows No, but with WSL and Git Bash, it can run on Windows hosts No. But is still installed as a secondary shell
POSIX compliance Yes, 100% No. But is still installed as a secondary shell
Auto-completion Basic level Advanced level
Support for plugins Limited support Advanced support using Oh My Zsh
Syntax highlighting No, basic CLI Yes
Scripting capabilities Powerful Offers more customization for an intuitive scripting experience
Customization Very limited Advanced customization
Speed Very fast Fast, but can slow down with loads of plugins
Popularity Very popular because it has more default support Also popular, especially for power users

Scripting capabilities

  • Bash — Due to its POSIX compliance and speed, Bash is better suited for scripting and automation
  • Zsh — Offers more customization for an intuitive scripting experience but lacks universal acceptance due to its POSIX limitation

Auto-completion and command history

  • Bash — Uses a simple tab and interface, making it the go-to for users who are more focused on performance

  • Zsh — Utilizes a menu interface like an IDE, with command history

Plugin and theme support

  • Bash — Offers very limited support for additional plugins
  • Zsh — Allows for the use of plugins and theme customization, with the Oh My Zsh framework

Syntax highlighting and visual enhancement

  • Bash — Does not colourize commands and text. This means that users would have to know their onion when scripting with bash

  • Zsh — Uses plugins to colourize its commands, setting distinctions to help users understand what they are writing better

Performance and memory usage

  • Bash — Lightweight and fast
  • Zsh — Heavy when laced with plugins

Choosing the right shell: When to use Bash vs. Zsh

To get the best experience, it is necessary to understand how the strengths of each align with your individual needs.

You should use Bash if:

  • You need to write scripts that would have to be run on multiple systems without modification
  • You need to write scripts that are expected to be fast, simple, yet effective
  • You need to write scripts that must stick to POSIX compliance
  • Your system is a legacy system, as Bash has more support for older systems
  • You are new to the use of command line shells, as Bash has a simpler learning curve

You should use Zsh if:

  • You prefer auto-completion and command history
  • You spend a lot of time in the terminal and would love an interactive usage
  • You want to use extensive plugins for advanced purposes
  • You are a power user who prefers customization and syntax highlighting on your CLI

What is Bash (Bourne Again Shell)?

Bash, renowned for its simplicity and versatility, was originally a part of the GNU project of 1989, which remodified it from the old Bourne Shell. Over the years, Bash has been the most widely used shell, adopted by most Linux systems and MacOS. However, starting with MacOS Catalina in 2019, Zsh replaced Bash as the default shell.

Core features and strengths of Bash

POSIX compliance

Bash’s POSIX compliance nature has made it possible for Bash scripts to be easily ported on virtually all Unix systems.

Lightweight, simple_,_ and stable

Bash is lightweight, enabling it to run efficiently on resource-low systems. With such a straightforward syntax, Bash is an excellent choice for many users who prioritize simplicity without compromising on features.

Scripting capabilities

Though it can be used for a variety of things, Bash is ideally used for scripting and automation.

Cross-platform compatibility

Bash is the default on most Linux distros and can also be used on MacOS and Windows via the Windows Subsystem for Linux(WSL).

Default shell status

Bash is found on nearly every Unix-like system, making it easier for users of these systems to start using it without going through the process of installation.

Common use cases for Bash

System administration and task automation

Bash can be used to run system admin functions like maintenance, and monitoring of system resources like RAM, CPU, and disk management. Additionally, it is used to manage system users, permissions, and privileges.

Writing scripts for Linux and macOS environments

On Unix-based systems like Kali and MacOS, Bash can be used to create automation for routine tasks, build and compile software, or even write execution scripts for software.

Networking administration

The Bash shell can be used to configure, test, and manage system networks, and communicate with remote systems via SSH setup firewalls.

Automation

Automation is a very big part of the command line interface, and the Bash shell is useful in both writing and executing scripts used to create system automation. Processes like backups, generating reports, and processing data at intervals. Its access to system resources, advanced yet simple style of commands, and native integration into Unix systems make it an effective shell.

Setting up Bash

If you use a system where Zsh or CMD is the default shell but would like to use Bash, here is a quick guide to help you set it up:

Bash for Windows

You can use Bash on a Windows host using different methods as highlighted in the table above. The most straightforward way — especially for individuals having issues with using the Windows Subsystem for Linux due to virtualization — is by using Git Bash.

Git Bash is an app for Windows computers that allows Windows users to have a Git CLI experience.

Go to the Git Bash download page, and download the latest version: git bash download page After downloading, install the application. During installation, stick to any installation checkbox that is recommended, except if you need a specific feature that can be configured during the installation process: git bash installation page Once fully installed, from your search bar, search for Git and click on Git Bash as an administrator: git bash administrator Once everything is settled, and your Bash opens, you should see this: screen when bash opens This is where you can utilize Bash functions as a Windows user.

Bash for Mac

If you are a Mac user, you should know that while Zsh replaced Bash, it only did so as the default shell. Thus, Bash still exists in MacBooks. Their coexistence is similar to how CMD and PowerShell are both existing in Windows hosts, with the user having the ability to choose their default shell.

To use Bash as the default on your Mac, you can type in Bash on your terminal. This will configure the terminal to recognize any commands typed afterwards as a Bash command, until that session is closed. Alternatively, you can turn it as your default shell by using the change shell command:

chsh -s /bin/bash
Enter fullscreen mode Exit fullscreen mode

The chsh is the command for changing the shell, the -s command specifies the shell you are changing to, and the /bin/bash is your shell’s path.

It is worth noting that the Bash used on Mac is outdated. You may have to manually install the latest version to enjoy more up-to-date features. To do that, use the package manager of Mac by typing brew install bash.

Essential Bash commands

Command Description
pwd Show current directory
cd [dir] Change directory
ls List files
cp \[src\] [dest] Copy file/directory
mv \[src\] [dest] Move/rename file/directory
rm [file] Remove file
mkdir [dir] Create directory
touch [file] Create an empty file
cat [file] Show file content
head [file] Show first lines of a file
tail [file] Show last lines of a file
grep \[pattern\] [file] Search pattern in file
find [path] -name [pattern] Find files by name
chmod \[permissions\] [file] Change file permissions
ps Show running processes
top Real-time process monitor
kill [PID] Kill a process by ID
df Show disk space usage
free Show memory usage
ping [host] Test network connectivity
curl [URL] Transfer data from/to server
tar -czf \[archive\] [dir] Create a compressed archive
tar -xzf [archive] Extract a compressed archive
echo $[var] Show environment variable value
export [var]=[value] Set an environment variable
history Show command history
diff \[file1\] [file2] Compare files
fdisk -l List disk partitions
mount \[device\] [dir] Mount a device

What is Zsh (Z Shell)?

Zsh (Z Shell) is a Unix shell that is an improved and more sophisticated alternative to the default Bash shell. Developed in 1990, Zsh borrows features from the Korn Shell (ksh) and the C shell (csh) but adds more sophisticated features like improved tab completion, better scripting, and personalization. The flexibility and Bash-command compatibility of Zsh made it the go-to for most developers.

Apple replaced the default shell on macOS from Bash to Zsh in 2019 with macOS Catalina since Zsh possesses more contemporary features and better long-term support.

Core features and strengths of Zsh

Advanced auto-completion

One of Zsh's biggest strengths is that it comes with context-aware autocompletion built into its shell environment for commands, paths, and arguments.

Spelling correction

Aside from its spelling correction, Zsh also corrects typos and suggests previously used text as you type, saving time and helping newbies write scripts more efficiently.

Enhanced globbing

Though Bash comes with wildcard matches, the one of Zsh is more powerful and accurate. For example, ls **/*.txt would search for all txt files in the current working directory.

Plugin and theme support

Zsh comes with better customization on the prompt, command, and shortcuts. Additionally, it supports Oh My Zsh, a framework that allows Zsh users to access thousands of plugins for extra customization, some of which include Git, Docker, and even Python.

Among its customization benefits, it also permits users to tweak their zshrc file to modify shell behaviour.

Syntax highlighting

Its superior syntax highlighting makes it easier for Zsh users to distinguish between commands and parameters in the shell.

Common use cases for Zsh

Interactive terminal use for developers

Developers who spend a lot of time in the terminal would benefit from its autosuggestions, fuzzy searching, and typo correction. Multiple plugins support streamlining their workflow and save time.

System admin and server management

While Bash can originally perform these actions, Zsh also has the ability to perform server management and system administration using its commands. This helps ensure the MacOS Kali users with Zsh as their default shell can better manage foreground and background processes.

DevOps and cloud management

Its plugin support lets Zsh users manage cloud and DevOps services, especially for Terraform and AWS CLI users.

In general, users who require advanced functionalities and extra customization for an intuitive flow would love its rich plugin support, high theming, and intelligent completion. While users who want to stick to the conventional smart way of doing more with fewer configurations would benefit from Bash and its built-in features.

Setting up Zsh

Zsh is the default on Mac. Thus, we won’t be discussing its installation for Mac users in this section. Rather, we would explore using Zsh on Windows and Linux systems that don’t have it as the default shell.

Zsh for Windows

Zsh, just like Bash, can be run on Windows using similar methods. WSL and Cygwin.

Download Cygwin from the official site by first downloading the .exe file. Click on the downloaded .exe file to get the full package: downloading the cygwin package During installation, type in Zsh as the shell you want to get, and click Next: cygwin setup

Zsh for Linux and Windows users (via WSL):

If you prefer using WSL, install it via the command wsl - - install. Once installed, you can use the sudo command to install Zsh. This also applies for Linux users:

sudo apt update && sudo apt install zsh -y
Enter fullscreen mode Exit fullscreen mode

sudo is used for superuser access. The -y is used for smooth installation, as it automatically answers YES for every question asked during installation. If you'd prefer to manually install and inspect it, you can skip that param.

After installation, verify that your installed tool is installed with this command: zsh -- version.

Once your installation is completed, you can then proceed to make it your default shell using chsh -s $(which zsh).

Configuring Zsh with Oh My Zsh

Oh My Zsh is an open-source Zsh framework used to add extra functionalities for Zsh, turbocharging the entire Zsh user experience. Oh My Zsh’s extra advanced features cause users who frequently use the terminal to gravitate towards Zsh.

Installing Oh My Zsh

To install Oh My Zsh from your Zsh terminal, you can either use curl, fetch,or wget.

Using curl:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Using fetch:

sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Enter fullscreen mode Exit fullscreen mode

Using wget:

sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Enter fullscreen mode Exit fullscreen mode

If for some reason, you are unable to use the raw.githubusercontent.com, kindly replace the entire command with https://install.ohmyz.sh/.

After Oh My Zsh has been installed, restart your terminal to effect the changes.

Popular plugins for productivity

  • Auto-suggestions — Zsh lets you easily use previous commands by utilizing context-aware technologies

  • Use aliases — Oh My Zsh uses aliases to define commands, making remembrance easier

  • Track directories — Users who have Oh My Zsh installed can use the Z command to track their most visited directories

  • Web search — Lets users make web searches on Google, Bing, and YouTube (e.g. google oh-my-zshor web-search google oh-my-zh)

Optimizing Zsh performance

Due to the number of plugins Zsh supports, it can run very slowly. Users who may require both speed and advanced customizations may be caught in a loop on which to choose.

Luckily for them, just as VS Code extensions can be disabled to make them lighter, the same can be said for Zsh (Oh My Zsh).

Disabling Zsh’s plugins can be quite tricky, but you have to understand that you should not delete the script itself — just the plugins. You can either do this via the command method or by manually deleting from the file.

The command method of disabling a plugin is: omz plug-in disable [plugin name]. i.e. omz plug-in disable git.

To confirm that your plugin is disabled, run omz plugin list.

The manual method of removing your plugin is via the zshrc file. Open the file via the command nano ~/.zhsrc Locate the plugin line and remove the plugin you want from this list, then exit the file.

Conclusion

Bash and Zsh are both important tools for scripting and working around different things in the interactive shell, but their distinctive differences make each shell more applicable for users with different needs.

Ultimately, those who love simplicity and just want to get their stuff done would choose Bash. Advanced users (or those whose work has turned the terminal their second home) might gravitate towards Zsh.

But then, there is no crime in having both running on the same system, right? That’s one thing Mac users enjoy out-of-the-box. But regardless of your system, you can still run any or both of these powerful shells with just some minimal workarounds, which have been explored here.


Get set up with LogRocket's modern error tracking in minutes:

  1. Visit https://logrocket.com/signup/ to get an app ID.
  2. Install LogRocket via NPM or script tag. LogRocket.init() must be called client-side, not server-side.

NPM:

$ npm i --save logrocket 

// Code:

import LogRocket from 'logrocket'; 
LogRocket.init('app/id');
Enter fullscreen mode Exit fullscreen mode

Script Tag:

Add to your HTML:

<script src="https://cdn.lr-ingest.com/LogRocket.min.js"></script>
<script>window.LogRocket && window.LogRocket.init('app/id');</script>
Enter fullscreen mode Exit fullscreen mode

3.(Optional) Install plugins for deeper integrations with your stack:

  • Redux middleware
  • ngrx middleware
  • Vuex plugin

Get started now.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay