How to query the current shell versions and types under the Linux command line

Source: Internet
Author: User
Tags echo command

There are several ways to see what shell you are currently using, and the easiest way is to use the shell's special parameters.

First, a special parameter named "$$" represents the PID of the shell instance that you are currently running. This parameter is read-only and cannot be modified. So, the following command will also show you the name of the shell you are running:

The code is as follows:

$ ps-p $$
PID TTY Time CMD
21666 PTS/4 00:00:00 Bash

The above commands work in all available shells.

If you don't use CSH, another way to find the shell currently in use is to use the special parameter "$", which represents the name of the shell or shell script that is currently running. This is a special parameter for Bash, 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.

The code is as follows:

$ echo $
Bash

Don't be fooled by a separate environment variable called $SHELL, which 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, even if you call a different shell in a terminal, the $SHELL remains unchanged.

The code is as follows:

$ echo $SHELL
/bin/shell


So, to find the current SHELL, you should use $$ or $ $, but not $SHELL.

Find the version of the current Shell
Once you know which shell you are using, you may want to know the version of the shell. To do this, enter the shell at the command line and add the "--version" parameter to view the version information later. For example:

For bash Shell:

The code is as follows:

$ bash--version
GNU Bash, version 4.3.30 (1)-release (X86_64-PC-LINUX-GNU)
Copyright (C) 2013 Free Software Foundation, Inc.
License gplv3+: GNU GPL version 3 or later
This is free software; You are are free to change and redistribute it.
There is NO WARRANTY and to the extent permitted by.
For the zsh Shell:

$ zsh--version
Zsh 5.0.7 (X86_64-PC-LINUX-GNU)

For TCSH Shell: $ tcsh--version

The code is as follows:

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).

The code is as follows:

$ echo $BASH _version
4.3.8 (1)-release

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.