82

Let's say, I opened a terminal and entered / executed some shell commands.

But I didn't invoke explicitly Bash or any other shell.

What shell was used by default?

BuZZ-dEE
  • 14,573

6 Answers6

76

The one specified on your line in /etc/passwd (it is a : separated line and the shell is the final one).

For example mine:

chris:x:1000:1000:Chris,,,:/home/chris:/bin/bash

Here it is /bin/bash (the Ubuntu default)

You can also use chsh:

$ chsh
Password: 
Changing the login shell for chris
Enter the new value, or press ENTER for the default
        Login Shell [/bin/bash]:

This is telling me my shell is /bin/bash and letting me change it.

Finally, echo $SHELL will do the same:

$ echo $SHELL
/bin/bash
BuZZ-dEE
  • 14,573
Caesium
  • 16,237
  • if it's bash, why is it sometimes invoked explicitly like sudo bash -c "netstat -an | grep LISTEN | grep -v ^unix" ?? – DrStrangeLove Dec 14 '11 at 23:25
  • I think that's a bad command personally - none of that even requires root. If it did, it would be better written as sudo netstat -an | grep LISTEN | grep -v ^unix. I see no reason to enclose that in a bash subshell. – Caesium Dec 14 '11 at 23:30
  • 2
    @DrStrangeLove: If more than one command in the pipe needed root permissions, then sudo bash -c "..." would ensure that the entire pipe is executed by root. – Keith Thompson Dec 15 '11 at 00:51
  • If you don't know which commands require root (and why), you shouldn't run them. Otherwise, why trust any command/program/script any more than is required. If you can't commandA | sudo commandB | commandC, you could do a sudo id first (runs the id command as root, but also acquires a "use sudo without password prompt" token that lasts for (default) 15 minutes. – waltinator Dec 20 '11 at 04:10
  • Duh! sudo -v refreshes the token without all the effort of running id. – waltinator Dec 20 '11 at 04:25
  • 2
    If you use chsh then you must log out and log back in to see this change. – Neil Traft Jul 06 '14 at 22:01
  • You can quickly test if everything works by switching to TTY1-7 user Ctrl+Alt+F1 – alexandre-rousseau Jun 12 '19 at 08:29
31

typing the following will display what shell the terminal opened with:

echo $SHELL

However, to find out what shell you are currently in (you may have changed it) type

ps -p $$

e.g. you will see that the shell is bash in the example output

  PID TTY          TIME CMD
 3500 pts/0    00:00:01 bash

Another method is to use

echo $0

this will simply return the name of the current shell.

fossfreedom
  • 174,664
  • Great answer! Thanks, for some reason echo $SHELL did not work (always used that one) and your two alternatives worked. Thanks! – AturSams May 04 '16 at 10:12
21

GNU Bash is the shell used by default in terminals on Ubuntu. However when scripts are executed on system boot then dash is used, as it is dash that is /bin/sh.

This is defined in the $SHELL environmental variable. You can check by typing echo $SHELL in the terminal.

Anonymous
  • 12,009
6

By default it's bash:

env | grep ^SHELL=

In most cases will produce

SHELL=/bin/bash
wojox
  • 11,870
  • 1
    Not necessarily. If you create a new user with useradd, it defaults to sh. $ useradd -D|grep SHELL SHELL=/bin/sh. – Sparhawk Apr 10 '14 at 06:48
  • +1, because although the selected answer requires less typing, it's always nice to have more than one way to do something. –  Sep 24 '16 at 15:45
4

To get file path of current shell executable one can use

readlink -f /proc/$$/exe

Some possible outputs are:

  • /bin/bash
  • /usr/bin/bash
  • /usr/bin/zsh
  • /home/victor/.linuxbrew/Cellar/zsh/5.2/bin/zsh
0

Easiest way to check your terminal is by using pinky command:

pinky -l YourUsername

to change your default shell as the above answers already did, use chsh or manually edit /etc/passwd

assaabriiii
  • 105
  • 1
  • 7