Home Linux How to determine Shell

How to determine Shell

by Anup Maurya
2 minutes read

There are many different shells available in Unix and Linux environments, and it is important to determine which shell you are using before you start writing shell scripts or executing shell commands. In this tutorial, we will cover some common ways to determine the shell that you are currently using.

Using the echo command

One of the easiest ways to determine the shell that you are using is to use the echo command to print the value of the $SHELL environment variable. The $SHELL environment variable contains the path to the shell that is currently being used.

To print the value of the $SHELL environment variable, simply run the following command:

$ echo $SHELL

This will print the path to the shell that you are currently using, such as /bin/bash or /bin/zsh.

Using the ps command

Another way to determine the shell that you are using is to use the ps command to list all the processes that are currently running on your system. The ps command can be used to display a wide range of information about each process, including the name of the shell that is being used.

To use the ps command to determine the shell that you are using, simply run the following command:

$ ps -p $$

The $$ symbol is a special shell variable that contains the process ID of the current shell. The ps -p command tells ps to display information about the process with the specified process ID.

The output of the ps -p $$ command will include a column called CMD, which contains the name of the command that started the process. The name of the command will be the name of the shell that is being used.

Using the env command

The env command is used to display a list of all the environment variables that are currently set in your shell. The $SHELL environment variable should be set to the path of the shell that is currently being used.

To use the env command to determine the shell that you are using, simply run the following command:

$ env | grep SHELL

This command will display the value of the $SHELL environment variable, which should be set to the path of the shell that is currently being used.

Conclusion

Determining the shell that you are using is an important first step when working with shell scripts or executing shell commands. There are many different ways to determine the shell that you are using, including using the echo command to print the value of the $SHELL environment variable, using the ps command to list all the running processes and looking for the shell command that started the current process, and using the env command to display the value of the $SHELL environment variable.

related posts

Leave a Comment

Enable Notifications OK No thanks