40

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?

  • tcsh/csh has its current shell in $shell – HongboZhu Jul 3 '19 at 13:19
49

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

|improve this answer|||||
  • Do you know how can I check that which config file is loaded? (which bashrc) – coffeMug Oct 16 '13 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 Oct 16 '13 at 13:26
  • I have a script which starts this bash shell from a tcsh shell. – coffeMug Oct 16 '13 at 13:28
  • 4
    Why not just ps $$ – cjm Oct 16 '13 at 15:13
  • 1
    @cjm why not indeed, answer edited. – terdon Oct 16 '13 at 15:17
9

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.

|improve this answer|||||
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
|improve this answer|||||
1

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.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.