This quick tutorial shows how to check the running shell, available shell in the system and how to change the default shell in Linux.
You probably are already aware that there are several shell available on Linux and other Unix-like systems. Bash is the default shell on almost all the Linux distributions but there are some other popular shells available such as:
Some of the shells provide additional features in a more user-friendly way. Take Fish shell for example. It partially starts showing you command hints based on your previous typed command. It’s quite handy if you don’t want remember the Linux terminal shortcuts all the time.
Let’s see a few things around shell in your Linux system.
How to know the default shell?
To know the default shell set for you in your Linux system, you can check the SHELL environment variable. Usually, the default shell is bash and it is shown like this:
How to see what shell are you currently using?
There is no single method that will tell you which shell you are using with 100% accuracy.
You can try either echo $0 that shows you an output like this:
or check the process using ps -p $$ like this:
ps -p $$
PID TTY TIME CMD
9625 pts/0 00:00:00 zsh
How to see all the shells available on your Linux system?
# /etc/shells: valid login shells
How to change the shell to use another one?
If you want to use a different shell, you can simply type its name and you’ll be logged into the new shell. For example, if you install zsh and want to use it, you can simply use:
You can enter exit to exit from the new shell and return to the previous one.
How to change the default shell in Linux permanently?
Suppose you liked the Fish shell a lot and you want to use it as your default shell so that every time you open the terminal or ssh into the system, you are using it instead of the default bash shell.
Linux allows you to change the default shell using the chsh command. The best way to change the default shell for you own logged in user is by specifying the shell name listed in the /etc/shells file with the -s option.
chsh -s /usr/bin/fish
You must log out of the system so that the changes take into effect otherwise you’ll think that running chsh didn’t change the shell.
Did you notice that I had to specify the full path as it was listed in the /etc/shells file? If I had used chsh -s fish, it would have given me an error like “chsh: fish is an invalid shell”.
Which shell do you like?
Now that you know how to change shell, you may also read how to change users in Linux.
I hope this little article helped you to change the shell in Linux. If you have thought about changing the default shell, perhaps you use something other than the bash shell. Which shell is it? Why do you prefer it over the others?
Do share your views in the comments below.