What is 'bash' command in bash?

bash is a command interpreter, a shell, a program with an interface that interprets the commands that you put into it.

When you call bash from bash, you simply start a new shell 'inside' the original shell. When you exit from this second shell, you return to the original shell. You can exit from each shell with the exit command.


There is a difference between shells and terminal emulators.

Shell is a thing that passes your commands to the kernel, and that is executed. And terminal emulator programs let you interact with the shell. Examples of Terminal emualtors are gnome-terminal,konsole and shells are bash,zsh,sh etc. Terminal emulators are simply named as Terminal in most desktop environments.

When you open Terminal, it uses a shell by default. For most terminals it is bash. You can change the default shell. First run whoami to get your user name. Then run cat /etc/passwd | grep user_name where user_name is your user name. The last word is your default shell. Now you can change your shell with sudo usermod --shell /bin/shell_name user_name.

Also when you type bash it just opens another shell. You can simply exit the other shell by running exit. Such as executing zsh or sh will take you to other shell. You can read the man pages of shell with man shell_name to learn the differences between shells. However the man pages are extremely large and complicated to read that it will make your head spin. Executing a man shell_name | wc -l will give you the line count.

Hope that helps


When you run bash in an existing shell, this starts a new bash shell as a child process of the one you were using.

You can see this in your Linux environment with the ps command:

    $ ps xjf
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
20282 20286 20282 20282 ?           -1 S    26075   0:00 sshd: john@pts/0
20286 20287 20287 20287 pts/0    32674 Ss   26075   0:00  \_ -bash
20287 32135 32135 20287 pts/0    32674 S    26075   0:00      \_ bash
32135 32674 32674 20287 pts/0    32674 R+   26075   0:00          \_ ps xjf

The reason you have to type exit twice to get out is that the first exit is exiting the child bash (process ID 32135 in this example), then the second exits the original bash (PID 20287 here).

If for some reason you wanted to start a new bash (or other shell) and knew that you were not going to want to return control to the original (parent) bash shell but instead to end your session, you could start the new bash via the exec command, which replaces your current running shell with the new process. (it actually keeps the same process ID, even if you change to a new shell like ksh via the exec command):

$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
john      3463 20287  0 13:47 pts/0    00:00:00 ps -f
john     20287 20286  0 06:11 pts/0    00:00:00 bash
$ exec ksh
$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
john      3471 20287  0 13:47 pts/0    00:00:00 ps -f
john     20287 20286  0 06:11 pts/0    00:00:00 ksh

(note both the original bash and the ksh that replaced it have PID 20287)

By using exec this way, when you exit the child bash, the parent has already gone, so you will end your session.

Side notes: One benefit of the exec bash is a quicker logout.

exec also uses less resources because the original shell has been replaced (the opposite of a bash fork bomb which consumes resources by starting many shells)

Beyond just launching shells, exec can let you give someone else access to something via your login, and make sure they're not left in your shell after they exit - e.g. I go to a colleague's desk, login as me and exec sudo (some command) or exec ssh (somewhere else) for them. Once they end that, it closes their terminal session instead of dropping them back to my login shell. (...but don't mess up logging in, or it will close your session when it would have normally returned to your shell)