We compare the Bash, Zsh, and fish shells
Bash, fish, and Zsh
Although all three shells follow the Posix standard, only Bash officially follows it. Bash even comes with a corresponding mode that adheres even more strictly to the Posix specification and, for example, ignores Bash's own configuration files [5].
Command input in all three shells leans either on Emacs or vi. You will also find that they all support a multiline mode that lets you input commands that span several lines.
Bash, fish, and Zsh will colorize the individual components of a command, if so desired, and the color scheme can be customized. Fish even supports the use of up to 16.8 million colors. You can redesign the prompt structure in all three shells.
In Zsh, every action at the prompt executes a widget. For example, Esc+B calls a widget that lets you move the cursor to the beginning of the word. You can create your own widgets.
All three shells remember every command you input. You can use a keyboard shortcut to call up older commands from this history. By default, Zsh remembers only the last 30 lines and also discards the list on exiting. If necessary, you can change this setting so that all open shells share a history (see the section on configuring Zsh later in this article).
On request, Bash, fish, and Zsh will complete a partially typed command. Autocompletion is designed to complete the names of variables, users, hosts, and files. In all three shells, it is possible to add your own rules to this function.
Bash and Zsh also offer limited spellchecking, with the Zsh acting in a far more intelligent way. Bash, for example, only corrects file names after cd
, but Zsh also corrects misspelled program names and other misspellings. Fish, on the other hand, suggests a possible command from the history while typing and highlights (typing) errors in red.
String of Pearls
Variables are used to record data. In Bash or Zsh, you do this by defining, for example, color=red
, and in fish, you need the set
keyword for this purpose:
set color red
The equals sign between the name and the value is also missing in fish, which makes the two methods incompatible.
Bash, fish, and Zsh can all store multiple values in arrays. Depending on the variant, these arrays are internally called lists, fields, or vectors. An element in an array is accessed by specifying its position:
colors[1]=red
In both Bash and Zsh, the count starts at zero. In the example, the word red
would therefore be stored in position two in the colors
array. In contrast, fish starts at one, which would mean that red
is the first element in the array in the preceding example.
In addition, fish supports the ..
operator, which you can use to access multiple elements at once:
echo $colors[2..4]
In this example the colors at positions 2
, 3
, and 4
of the array would be output.
Substitution
All shells are capable of command substitution, which lets you substitute one command for another. In the following example, Bash and Zsh would first execute the date
command and then pass the returned value as a parameter to the mkdir
command:
mkdir $(date +"%Y-%m-%d")
In older code, you can often find the now obsolete notation with backticks `date +"%Y-%m-%d"`
. fish makes the code more readable. It does not support either variant but requires simple brackets:
mkdir (date +"%Y-%m-%d")
Using the same principle, shells integrate the contents of variables into texts. In Bash and Zsh, you put the variable in curly braces as follows:
ls letter${date}.txt
However, fish again does its own thing with slightly different syntax:
ls letter{$date}.txt
Bash, fish, and Zsh provide some predefined and special variables, but they differ from shell to shell. For example, Bash and Zsh users will find the first parameter passed to the script on the command line in the variable $1
. Fish, on the other hand, does not support a $1
variable, so you will need to extract all the transferred parameters from the $argv
array if needed.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.