What Shell Am I Using? Identify Your Shell
In this article
You are most likely using Bash (Bourne Again Shell) if you are on Linux or macOS, or PowerShell if you are on Windows. To find out exactly, run echo $0 on Unix-like systems or $PSVersionTable.PSVersion in PowerShell.
Why Your Shell Matters
The shell is the command-line interpreter that translates what you type into actions the operating system performs. It affects how you write commands, scripts, and automate tasks. Different shells have different syntax, built-in functions, and behaviors. Knowing which one you are using helps you write correct commands and avoid errors when copying instructions from the web or collaborating with others.
How to Check Your Current Shell
There are several ways to identify your active shell. The method depends on your operating system and whether you are in a terminal, a script, or a remote session.
- Unix-like (Linux, macOS): Run
echo $0– it prints the name of the current shell. Alternatively,ps -p $$shows the process name and PID of the shell. - Windows PowerShell: Run
$PSVersionTable.PSVersionto see the version, or$PSCommandPathto see the script path. The shell name is always PowerShell, but the version matters. - Windows Command Prompt (cmd): The shell is cmd.exe. You can verify with
echo %COMSPEC%. - Inside a script: Use
$0in Bash or$MyInvocation.MyCommand.Namein PowerShell to see the script's own name, not the shell.
Common Shells and Their Characteristics
Each shell has its own strengths and quirks. Here are the most common ones you will encounter.
- Bash (Bourne Again Shell): The default on most Linux distributions and macOS (before Catalina). It is a superset of the original Bourne shell (sh) and supports command-line editing, job control, and functions.
- Zsh (Z Shell): The default on macOS since Catalina. It is highly customizable, with features like spelling correction, shared history, and advanced globbing. It is largely compatible with Bash.
- Fish (Friendly Interactive Shell): Known for its user-friendly features like autosuggestions, syntax highlighting, and a simpler scripting syntax. It is not POSIX-compliant, so Bash scripts may not run directly.
- PowerShell: Microsoft's shell and scripting language built on .NET. It uses objects instead of text streams, making it powerful for system administration. It runs on Windows, Linux, and macOS.
- Command Prompt (cmd.exe): The legacy Windows shell. It is simple but lacks many features of modern shells, such as command-line editing and scripting capabilities.
How to Change Your Default Shell
If you prefer a different shell, you can change your default. On Unix-like systems, use the chsh command. On Windows, you can set PowerShell as the default terminal application or use the Command Prompt properties.
- Find the full path to your desired shell. For Bash, it is usually
/bin/bash. For Zsh,/bin/zsh. - Run
chshand enter your password when prompted. - Enter the path to the new shell (e.g.,
/bin/zsh). - Log out and back in for the change to take effect.
On Windows 10 and 11, you can set the default terminal application in Settings > Privacy & Security > For developers, or by using the Windows Terminal settings.
Common Problems and Misconceptions
One frequent issue is that a script written for Bash fails in Zsh or vice versa. For example, the source command works in both, but the echo built-in behaves slightly differently. Another misconception is that sh is always Bash – on many systems, sh points to Dash (Debian Almquist Shell), which is faster but has fewer features. When you run a script with ./script.sh, the shebang line (#!/bin/bash) determines the interpreter, not the shell you are currently using. If you see an error like bad interpreter: No such file or directory, it means the shebang points to a shell that does not exist.
How to Choose the Right Shell for Your Work
Choosing a shell depends on your needs. If you are a system administrator on Linux, Bash is a safe choice because it is ubiquitous. If you are a developer on macOS, Zsh offers better autocompletion and theming. For Windows automation, PowerShell is the way to go because it integrates with the .NET framework and Windows management tools. If you want a modern, interactive experience, Fish is worth trying. The best approach is to test a few and see which one feels most productive.
Frequently Asked Questions
What is the difference between a shell and a terminal?
A terminal (or terminal emulator) is the graphical window that displays text and accepts input. The shell is the program that runs inside that window and interprets the commands. For example, GNOME Terminal is a terminal emulator, and Bash is the shell running inside it.
Why does echo $0 show -bash instead of bash?
The leading hyphen indicates a login shell. When you log in, the shell is invoked with a dash before its name, which causes it to read certain startup files like .profile or .bash_profile. A non-login shell (like one opened in a new tab) does not have that dash.
Can I run Bash commands in PowerShell?
No, not directly. PowerShell uses a different syntax. However, you can call Bash from PowerShell by typing bash if the Windows Subsystem for Linux (WSL) is installed, or you can use cmd /c to run a command in Command Prompt. But the commands themselves are not interchangeable.
How do I see the version of my shell?
For Bash, run bash --version. For Zsh, use zsh --version. For PowerShell, $PSVersionTable.PSVersion shows the version. For fish, fish --version.
Is it safe to change my default shell?
Yes, it is generally safe. The change only affects your user account, and you can always switch back. Make sure the new shell is installed and that you know its path. If you accidentally set a non-existent shell, you may not be able to log in, but you can usually fix it from a recovery console or by editing the /etc/passwd file (on Unix-like systems) with root privileges.