Most Linux users stick with the default shell, usually Bash. But Linux offers many other shells like Zsh, Fish, Dash, and Ksh. Each shell behaves a little differently and offers unique features. Learning to run multiple shells helps you write better scripts, debug problems, and choose the right shell for the job.
In this post, you’ll learn:
- Why you might want to use more than one shell
- Different ways to install and run multiple shells in Linux
- Smart tools and tips for testing across shells
Table of Contents
What is a Shell in Linux?
A shell is a program that runs commands you type into the terminal. It lets you talk to your system, run programs, manage files, and much more.
Linux supports many shells. Here are some popular ones:
Shell | Known For |
---|---|
Bash | Default on most Linux systems |
Zsh | Smart autocomplete and plugins |
Fish | User-friendly and modern |
Dash | Fast, simple, POSIX-compliant |
Ksh | Used in older Unix systems |
Why Use Multiple Shells?
Here are the main reasons:
1. Test Script Compatibility
Different Linux systems use different shells. Some shells support extra features. Others stick to strict POSIX rules.
A script that works in Bash may fail in Dash or Fish. Testing across shells helps you catch these problems early.
2. Pick the Best Shell for Your Work
- Use Zsh or Fish for daily commands. They’re fast and smart.
- Use Bash or Dash for writing scripts. They’re simple and predictable.
3. Explore and Learn
Trying different shells helps you understand how they work, how they differ, and how to write better commands.
How to Run Multiple Shells in Linux
You can run many shells on one system. Here are all the possible ways:
Method 1: Use Docker Containers (Recommended)
If you want a clean shell environment without affecting your system, use Docker. Docker makes testing shells super easy. You don't need to install anything on your main system, except the Docker of course.
If you haven't already, install Docker as described in the links given below:
- Install Docker Engine And Docker Compose In AlmaLinux, CentOS, Rocky Linux
- How to Install Docker And Docker Compose In Ubuntu
Basic Shell Testing
# Test with bash docker run --rm -it ubuntu bash # Test with fish docker run --rm -it ubuntu fish # Test with zsh docker run --rm -it ubuntu zsh # Test with multiple shells docker run --rm -it ubuntu bash -c "apt update && apt install -y zsh fish && zsh"
The last command does three things:
- Creates a new Ubuntu container
- Installs zsh and fish shells
- Starts zsh for testing
Exit the container when done. It will be automatically deleted. No changes are saved to your host system.
Best Practice: Dockerfile Approach
For repeated testing, I recommend you to use Dockerfile.
Step 1: Create a Dockerfile
Create a new file called Dockerfile
(no extension) in a new folder and paste your Dockerfile content into it.
mkdir multi-shell-container cd multi-shell-container nano Dockerfile
Add the following lines:
# Use latest Ubuntu as base image FROM ubuntu:latest # Set non-interactive mode to avoid prompts ENV DEBIAN_FRONTEND=noninteractive # Install all popular shells RUN apt update && apt install -y \ zsh \ fish \ dash \ ksh \ tcsh \ mksh \ yash \ busybox \ && rm -rf /var/lib/apt/lists/* # Set working directory WORKDIR /test # Default to bash shell CMD ["bash"]
Step 2: Build the Image
Build the image using docker command:
docker build -t multi-shell .
If you use podman, use this command instead:
podman build -t multi-shell .
Step 3: Run Container
Now, run the container using command:
docker run --rm -it multi-shell
Or,
podman run --rm -it multi-shell
This command drops you into a Bash shell inside the container.
(Optional) Override the Default Shell
Since the CMD
is set to bash
in the Dockerfile, the container starts in Bash by default. But you can override the default shell (bash
) and start with another shell installed in the image.
For instance, if you want to start a container with Dash shell by default, run:
docker run --rm -it multi-shell dash
Fish:
docker run --rm -it multi-shell fish
Ksh:
docker run --rm -it multi-shell ksh
Tcsh:
docker run --rm -it multi-shell tcsh
Zsh:
docker run --rm -it multi-shell zsh
Important Note: I have added --rm
flag to automatically remove the container on exit. If you want to keep the container, simply remove that flag.
Example:
docker run -it multi-shell zsh
Docker Compose
Using both a Dockerfile and a docker-compose.yml file together gives you a clean, flexible, and reproducible environment.
Here’s a simple docker-compose.yml
that runs your multi-shell image with Bash by default, and lets you easily switch shells if needed.
Step 1: Create Compose File
Create a new docker-compose.yml
file with the following contents:
version: "3.8" services: multi-shell: build: context: . dockerfile: Dockerfile image: multi-shell container_name: multi-shell-container stdin_open: true # for interactive terminal tty: true # for proper terminal behavior command: bash # default shell (can change to zsh, fish, etc.)
Put this docker-compose.yml
in the same folder as your Dockerfile.
Step 2: Build and Run the Container
Build the image using command:
docker-compose build
Run the container:
docker-compose run multi-shell
By default, you will land in the bash shell.
You can switch to another shells by entering:
fish zsh
Start Containers with Specific Shells
If you want to use a different shell, for example Zsh, run:
docker-compose run multi-shell zsh
Or update the command:
in the YAML file if you want a different default.
Now test all your scripts or apps in different shells.
Once done, remove the container and image using command:
docker-compose down --rmi all
Method 2: Install and Run Shells Locally
This is the easiest method. Just install the shells you want in your local system using the default package manager.
sudo apt install zsh fish dash ksh
Replace apt
with your system's default package manager.
Once installed, run a shell by typing its name:
zsh # Start Zsh fish # Start Fish dash # Start Dash
To go back to your default or previous shell, type:
exit
Change Your Default Shell (Optional)
You can change which shell starts when you log in:
chsh -s /usr/bin/zsh
Log out and back in to apply the change. Replace zsh
with any other installed shell.
Method 3: Use Virtual Machines (VMs) or Containers
This method is useful when testing across different distros or system setups. There are multiple applications exist to run entire Linux systems.
Some of the notable tools to run VMs are:
You can also use full featured virtualization platforms such as Proxmox or XCP-ng.
Run Commands Directly in Another Shell
After installing the shells using any one of the methods above, use -c
to execute a command in a different shell without switching:
bash -c 'echo $BASH_VERSION' zsh -c 'echo $ZSH_VERSION' fish -c 'echo $FISH_VERSION'
Use a Script to Test Commands Across Shells
Want to test a command in many shells? Use this simple script. Make sure you have installed the shells as shown in the above methods.
#!/bin/bash for sh in bash zsh fish dash; do if command -v $sh > /dev/null; then echo "=== Testing in $sh ===" echo 'echo Hello from $0' | $sh else echo "$sh not found" fi done
Save this as test-shells.sh
, make it executable, and run it.
Pro Tips for Using Multiple Shells
- Use
#!/bin/bash
(or#!/bin/sh
) at the top of scripts: Ensures the right shell runs them. - Check shell compatibility: Use shellcheck (a tool) to find errors.
- Keep configurations separate: Use
.bashrc
for Bash,.zshrc
for Zsh.
Summary: Best Way to Use Multiple Shells
Method | Use Case |
---|---|
Docker containers | Clean, safe environment |
Install locally | Easy, works offline |
Virtual machines | Test across OS versions |
Conclusion
Running multiple shells in Linux helps you:
- Write better, more portable scripts
- Choose the best shell for your work
- Understand how Linux really works
Start by installing Zsh or Fish alongside Bash. Then try a testing script or a container. You don’t need to switch completely, just explore and learn.