Getting started with Linux: How do I know which Shell is being used?
Problem: I often switch shell in the command line. Is there a quick and easy way to find out the shell I am currently using? In addition, how can I find the current shell version?
Find the Shell version you are currently using
There are multiple ways to view what shell you are currently using. The simplest way is to use special shell parameters.
First, a special parameter named "$" indicates the PID of the currently running shell instance. This parameter is read-only and cannot be modified. Therefore, the following command will also display the name of the shell you are running:
$ ps-p $$
PID TTY TIME CMD
21666 pts/400:00:00bash
The preceding command can work in all available shells.
If you do not use csh, another method to find the currently used shell is to use the special parameter "$0", which indicates the name of the currently running shell or shell script. This is a special Bash parameter, but it can also be used in other shells, such as sh, zsh, tcsh, or dash. Use the echo command to view the name of the shell you are currently using.
$ echo $0
bash
Do not be confused by an independent environment variable called $ SHELL. It is set to the full path of your default shell. Therefore, this variable does not necessarily point to the shell you are currently using. For example, $ shell remains unchanged even if you call different shells in the terminal.
$ echo $SHELL
/bin/shell
Therefore, to find the current shell, you should use $ or $0, but not $ SHELL.
Find the current Shell version
Once you know which shell you are using, you may want to know the version of this shell. Therefore, enter shell in the command line and add the "-- version" parameter to the end to view the version information. For example:
For bash shell:
$ bash--version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
Copyright(C)2013FreeSoftwareFoundation,Inc.
LicenseGPLv3+: GNU GPL version 3or later
Thisis free software; you are free to change and redistribute it.
Thereis NO WARRANTY, to the extent permitted by law.
For zsh shell:
$ zsh --version
zsh 5.0.7(x86_64-pc-linux-gnu)
For tcsh shell: $ tcsh -- version
tcsh 6.18.01(Astron)2012-02-14(x86_64-unknown-linux) options wide,nls,dl,al,kan,rh,nd,color,filec
For some shells, you can also use shell-specific variables (for example, $ BASHVERSION or $ ZSHVERSION ).
$ echo $BASH_VERSION
4.3.8(1)-release
Via: http://ask.xmodulo.com/which-shell-am-i-using.html
Author: Dan Nanni Translator: strugglingyouth Proofreader: wxy
This article was originally compiled by LCTT and launched with the honor of Linux in China
This article permanently updates the link address: