Getting started with Linux: How do I know which Shell is being used?

Source: Internet
Author: User
Tags echo command

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:

  1. $ ps-p $$
  2. PID TTY TIME CMD
  3. 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.

  1. $ echo $0
  2. 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.

  1. $ echo $SHELL
  2. /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:

  1. $ bash--version
  2. GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
  3. Copyright(C)2013FreeSoftwareFoundation,Inc.
  4. LicenseGPLv3+: GNU GPL version 3or later
  5. Thisis free software; you are free to change and redistribute it.
  6. Thereis NO WARRANTY, to the extent permitted by law.

For zsh shell:

  1. $ zsh --version
  2. zsh 5.0.7(x86_64-pc-linux-gnu)

For tcsh shell: $ tcsh -- version

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

  1. $ echo $BASH_VERSION
  2. 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:

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.