45

When I run echo $SHELL the output says /bin/tcsh which means that I am running a tcsh shell. But for example when I issue the following command

alias emacs 'emacs -nw' 

I get the following error:

bash: alias: emacs: not found
bash: alias: emacs -nw: not found

and when I issue alias emacs="emacs -nw" it runs fine!

This is confusing since I am running tcsh but the commands are interpreted by bash.

What could be the reason?

1
  • tcsh/csh has its current shell in $shell
    – HongboZhu
    Commented Jul 3, 2019 at 13:19

5 Answers 5

54

$SHELL is not necessarily your current shell, it is the default login shell. To check the shell you are using, try

ps $$

This should work on most recent Unix/Linux with a ps that supports the BSD syntax. Otherwise, this is the portable (POSIX) way

ps -p $$

That should return something like this if you are running tcsh:

8773 pts/10   00:00:00 tcsh

If you want to have tcsh be your default shell, use chsh to set it.

10
  • Do you know how can I check that which config file is loaded? (which bashrc)
    – Vombat
    Commented Oct 16, 2013 at 13:24
  • @Coffe_Mug not sure what you mean. You can set the default shell with chsh, .bashrc will only be read if you are i) running bash and ii) running it as an interactive, non-login shell. How are you logging into this machine?
    – terdon
    Commented Oct 16, 2013 at 13:26
  • I have a script which starts this bash shell from a tcsh shell.
    – Vombat
    Commented Oct 16, 2013 at 13:28
  • 4
    Why not just ps $$
    – cjm
    Commented Oct 16, 2013 at 15:13
  • 1
    @cjm why not indeed, answer edited.
    – terdon
    Commented Oct 16, 2013 at 15:17
10

From the command line, you can also use the $0 variable to determine which shell you are using. e.g.:

~$ echo $0
/bin/bash


~$ ksh
$ echo $0
ksh

Note: you cannot determine the shell using $0 within a script, because $0 will be the script itself.

2

This is an amendment to all of the better answers above. I had a tiny issue identifying dash at one point; seemed right to share:

curl -fsSL http://www.in-ulm.de/~mascheck/various/whatshell/whatshell.sh | sh
ash (dash 0.5.5.1 ff)

curl -fsSL http://www.in-ulm.de/~mascheck/various/whatshell/whatshell.sh | bash
bash 4.3.30(1)-release

Good for troubleshooting in tight spots is all. Cheers.

2
  • So it's using curl to download that script, and then it passes it to the shell you indicate after the pipe, and the script is such that by the way it is processed it is possible to understand what shell it is? Commented Oct 24, 2020 at 5:43
  • yeah, seems like you would already know which shell you're using but in the case you inherited a system with sh that could be Bourne shell, ash (Almquist shell) or dash (Debian Almquist shell) - and they all behave slightly different. UNIX was all over the place though; that was the whole reason for GNU. Bash is pretty much jut Bash; this will tell you a version but you can get that the normal way, bash --version or echo $BASH_VERSION. I just like how this script is a one-stop-shop for everything.
    – todd_dsm
    Commented Oct 25, 2020 at 17:20
1

This works for linux:

lsof -a -p $$ -d txt

or, if you need a stronger selection (more systems):

lsof -a +D /bin +D /usr/bin -p $$ -d txt
0

A Unix/Linux Operating System may have more than one shell installed. You can type the following command in your terminal to see which shell you are using:

Below is the list,

  • Bourne Shell – sh
  • C Shell – csh
  • T Shell – tcsh
  • Korn Shell – ksh
  • Bourn-again Shell – bash
  • Dash Shell
  • Z shell

This list is not complete and there are many other shells.

/etc/shells file stores list of all shells installed in your system. Simply, run the below command to find out the installed shells,

$ cat /etc/shells

Run grep command on /etc/passwd file to know the default shell when you log in to Unix or Linux operating system.

$ grep john /etc/passwd    

You can also use the $SHELL variable for the same purpose.

echo $0
$ echo $SHELL

The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal: When there are multiple shells installed on your system, you can always switch the shell.

so how do you know which shell you are running at the moment?

Simply use the below command

-bash
$ ps -p $$

I think all your questions are answered. If you still have a doubt, you can refer to this source article.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .