Linux Shell

A program that receives commands from the user through the keyboard and lets the OS execute them.

What Is a Shell?

A shell is a program that receives commands from the user and lets the operating system interpret and execute those commands.

The shell is a command interpreter that enables interaction between the user and the system. It generally sits around the kernel, the core of the operating system. Unix provides several types of shells, and users can choose the one that best fits their purpose and preference.

Types of Shells

Several shells are available on Linux. The following is a brief overview of commonly used shells. The default shell is usually set as the symbolic link at /bin/sh.

  • bash (Bourne-Again Shell) /bin/bash

    • Developed by GNU.
    • A feature-rich shell that supports command history, a directory stack, command substitution, and command/file-name completion.
    • Installed as a standard shell on most Linux systems.
  • csh (C Shell) - /bin/sh

    • Developed at the University of California, Berkeley.
    • A shell with syntax similar to the C language, mainly used on BSD-based operating systems.
  • ksh - /bin/ksh

    • Developed by David Korn.
    • A superset of the Bourne shell with a standard environment suitable for beginners.
    • A shell valued by users with Unix knowledge.
  • tcsh /bin/tcsh

    • An improved version of csh with completion features for commands and file names.
    • User-oriented and fast.
  • zsh (Z shell)

    • A fast shell that is compatible with bash.

Since macOS 10.15 Catalina, the default shell has changed from bash to zsh.*

Shell Commands

Check the Shell Currently in Use

You can check which shell is currently in use with the following command.

% env | grep SHELL
SHELL=/bin/zsh

You can also use this command:

% echo $SHELL
/bin/zsh

Check the Shells Installed on macOS

You can check the list of shells currently installed on macOS with the following command.

cat /etc/shells
% cat /etc/shells
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

Change the Shell in Use

You can use the chsh command to change the shell you use.

chsh -s /bin/bash
% chsh -s /bin/bash
Changing shell for user.
Password for user:

References