Bash is the most popular shell implementation program that most modern Linux systems like Debian and Ubuntu ship out of the box, unlike ZSH and Fish.
However, operating systems like Kali Linux and macOS took a step forward by providing ZSH as the default login shell for their systems because of its features and functionality.
Most of the time, Bash and its derivative shells like ZSH and Fish share common syntax and functionality, except for a few things that do not affect regular interactive users.
However, this minor difference might affect shell script writers who want to write script in Bash for mass users; having other shells might become a stepping stone in their way.
That’s why you should know all the shells in your and other systems, and as a shell script user, you should also know the existing shell in your Linux system.
Apart from them, a curious Linux user who wants to explore other shells can also check the existing available shells on their Linux system by following this guide.
Tutorial Details
Description | Listing All Available Shells in Linux |
Difficulty Level | Low |
Root or Sudo Privileges | No |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | cat, grep, awk, chsh, printenv, echo |
Internet Required | No |
Listing All the Available Shells in Your Linux System
There are several ways to find the available shells on your Linux system from the command line without requiring any extra tools, starting with
Reading the /etc/shells file
The traditional way to check all the available shells in your system is by reading the “/etc/shells
” file using the cat command.
$ cat /etc/shells
Output:
Using the Grep Command with Regular Expressions
The grep command with regular expressions will only list the shell path (that starts with a “/
” slash) in the “/etc/shells
” file, ignoring the first commented line.
$ grep '^[^#]' /etc/shells
Output:
Using the Chsh Command
The chsh command is usually used to change the default login shell, but the same command with the “-l
” or “--list-shells
” flag will list the available shells in your Linux system.
$ chsh -l
Output:
Listing Only the Single Result of the Duplicate Shell Occurrences
While reading the “/etc/shells
” file, it will list all the available shells in all known locations, with single shells appearing multiple times (due to different paths).
However, you can remove the path and use the shell names to print the unique result without repeating a single shell multiple times, as shown.
$ grep '^[^#]' /etc/shells | awk -F "/" '{print $NF}' | uniq
Output:
Command breakdown:
grep '^[^#]' /etc/shells
: It will list all the shell paths that start with a “/
” slash.awk -F "/" '{print $NF}'
: It will use the “/
” slash in the path as a separator to create different columns and list the last column containing the shell name.uniq
: List only the unique shell name without repeating it multiple times.
Listing All the Users with Their Default Login Shell
You can easily find out the default login shell for all users by reading the “/etc/passwd
” file using the awk command, as shown.
$ awk -F ":" '{print "User: "$1", Shell: "$7}' /etc/passwd
Output:
Note that this file also contains users created by the system services, applications, or programs that can give you some unnecessary information.
To filter out the result, specify the username with the grep command to find the default login shell for a specific user.
$ awk -F ":" '{print "User: "$1", Shell: "$7}' /etc/passwd | grep linuxtldr
The above command will only list the default login shell for the “linuxtldr
” user, as shown.
Printing the Default Login Shell for an Existing User
You can read the $SHELL environment variable or use the echo command to find out your own existing login shell, as shown.
$ printenv SHELL
#OR
$ echo $0
Output:
Final Tip!
The default login shell shipped with your Linux distribution will surely be present in this configuration file, and manually installed shells will also add their paths to this file.
However, in some rare situations, like when it happens to me when I install the Korn shell, the binary path of this shell is not added to this configuration file. In this case, I have to use the which command to find the binary path.
Still, it will rarely happen to you, but if it does, don’t hesitate to ask for help from us in the comment section.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.