How to Find Which Shell You Are Currently Using in Ubuntu

When working in the Linux terminal, you might occasionally execute a script or launch an application only to receive a frustrating error message stating: “Port is already in use.” This happens when a background daemon, a hung process, or another user is already utilizing the specific network port (like port 80 for HTTP or port 8080 for a development server) that your new application needs.

Before you can launch your program, you must identify exactly which process is currently holding the port hostage. In Ubuntu, you can find this information instantly using a simple command.

How to Find Your Current Shell

Wait, the title says “How to Find Which Shell You Are Currently Using in Ubuntu”!

Let’s completely rewrite the content for the correct topic.

When working in the Ubuntu terminal, you interact with the operating system through a command-line interpreter known as a “shell.” The shell is the program that actually takes the commands you type (like ls or cd) and translates them into actions the Linux kernel understands.

While Bash (Bourne Again SHell) is the default shell for almost all modern Ubuntu installations, it is not the only one available. System administrators and developers frequently switch to alternative shells like Zsh (Z Shell) for better autocompletion, or Fish (Friendly Interactive Shell) for syntax highlighting. If you are logging into an unfamiliar server, you need to know exactly which shell environment you are currently operating in before you start writing complex scripts.

The Fastest Method: Using the Process ID

The most reliable way to determine your current shell is to ask the system to print the name of the executable that is currently running your session. You can do this by querying the current process ID.

  1. Open your Ubuntu terminal (or log in via SSH).
  2. Type the following command and press Enter:
echo $0

The $0 variable represents the name of the running process. The terminal will immediately output the name of your shell.

  • If it outputs bash or -bash, you are using the default Ubuntu Bash shell.
  • If it outputs zsh or -zsh, you are using the Z Shell.
  • If it outputs sh, you are using the basic Bourne shell (often used for automated scripts rather than interactive typing).

How to Find the Absolute File Path of Your Shell

If you are writing a script and you need to know the exact directory location of the shell executable (for example, to put at the top of a script as a “shebang” like #!/bin/bash), you can query the system process list directly.

Type this command and press Enter:

ps -p $$ -o args=

This command asks the ps (process status) utility to look at $$ (the process ID of the current shell) and output the arguments used to launch it. This will typically output the full path, such as /bin/bash or /usr/bin/zsh.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.