VMware ESXi and vSphere Cluster Management
The Shell in Linux
Learn what a Linux shell is, how it differs from a terminal and kernel, why it matters, and how Bash, C shell, and Korn shell are used.
A shell is a program that reads commands, interprets them, and then runs programs or performs built-in operations. It provides a text-based way to interact with Linux, commonly called a command-line interface (CLI).
Instead of selecting an application or file with a graphical interface, you type a command at the shell prompt. The shell determines what that command means, finds the requested program when necessary, and starts the operation.
Shell, terminal, command line, and kernel
These terms are related, but they describe different parts of a Linux session.
| Component | Role | Example |
|---|---|---|
| Terminal emulator | Displays a text session and accepts keyboard input. | GNOME Terminal, Konsole |
| Shell | Interprets entered commands and runs programs or shell-built-in operations. | bash |
| Kernel | Manages system resources such as hardware, processes, and memory. | Linux kernel |
Terminal or console
A terminal emulator is an application that provides a text terminal session inside a graphical desktop. When you open GNOME Terminal, Konsole, or a similar application, the window is the terminal emulator. It normally starts a shell inside that window.
A console is a text-based system interface. It can refer to a local virtual console, a terminal session, or other text access to a Linux system. In everyday desktop use, people often use “terminal” for the application window and “shell” for the program running inside it.
Command line
The command line is the text-based method of entering instructions. The shell provides the command-line interface, and the terminal or console provides a place to see that interface and type into it.
Kernel
The kernel is the central component of Linux. It manages hardware, processes, memory, filesystems, networking, and other system resources. A shell does not replace the kernel. Instead, shell commands eventually cause programs or shell operations to request services from the operating system.
For example, the shell can start the ls program. That program asks the operating system for directory information, and the kernel helps provide access to the filesystem. Other commands, such as cd, are commonly built into the shell because changing the current directory must affect the shell process itself.
Graphical interface and shell interface
A graphical user interface (GUI) and a shell are two different interfaces for using Linux. A file manager provides graphical controls for browsing files, while commands such as pwd, ls, and cd provide text-based alternatives.
Why learn the Linux shell?
Linux distributions may provide a complete GUI, but shell access remains important for administration, automation, troubleshooting, development, and advanced work. Many instructions for Linux systems are written as commands because commands can be precise, repeatable, and used over a network.
From a shell, you can:
- Launch programs.
- Navigate directories and inspect files.
- Create, copy, move, rename, and remove files.
- Search and manipulate text.
- Inspect processes, storage, networking, and system information.
- Manage permissions and ownership.
- Install or update software when using the distribution's package tools.
- Automate repeated tasks with shell scripts.
- Administer remote systems through tools such as SSH.
Learning the shell provides a foundation for permissions, package management, scripting, standard input and output, pipes, redirection, environment variables, and remote administration.
Common Linux shells
Linux can run many different shells. A distribution, user account, or system administrator may choose one shell as a default, while other shells may also be installed.
| Shell | Common command name | Full name | Typical context or characteristic |
|---|---|---|---|
| Bash | bash | Bourne Again Shell | Widely used default interactive shell on Linux |
| C shell | csh or tcsh | C shell / enhanced C shell | Command syntax and interactive style historically influenced by the C language |
| Korn shell | ksh | Korn shell | Prominent in UNIX System V-related environments |
Bash
Bash means Bourne Again Shell. It is a widely used interactive shell on Linux and is often selected as the default shell, although that choice is not universal. Bash supports command history, tab completion, variables, redirection, pipelines, and scripting.
C shell
C shell is a family of shells commonly represented by csh and tcsh. Its command syntax and interactive style were historically associated with the C programming language. It is one option among several and is not interchangeable with Bash in every script or command.
Korn shell
Korn shell, commonly represented by ksh, is a UNIX shell family that became especially prominent in UNIX System V environments. It provides interactive features and scripting capabilities and remains available on some Linux systems.
Installed shells and default choices vary. The available shells depend on the distribution's packages, the system configuration, and the shells authorized for login. Different user accounts on the same computer can have different default shells.
A first Bash session
When a shell is ready for input, it displays a prompt. The prompt is text that indicates the shell is waiting for a command. Its appearance varies by configuration.
$ pwd
/home/alex
$ ls
Documents Downloads Pictures
$ echo "Hello from the shell"
Hello from the shell
In this example, the $ character is part of the displayed prompt; it is not normally typed as part of the command.
pwdprints the current working directory.lslists entries in the current directory.echoprints text.
You can also change directories:
$ cd /tmp
$ pwd
/tmp
The cd operation is typically a shell built-in. It changes the working directory of the current shell session.
Finding your current and default shell
After signing in or opening a terminal, a user normally receives a configured login shell. A login shell is the shell started when a login session begins. The default shell is the shell configured as the normal login shell for a user account.
The shell currently running and the shell configured for the account are related but can differ. A terminal can start a non-login shell, or you can manually start another shell inside an existing session.
Identify the current interactive shell
echo "$0"
This prints the name associated with the current shell session. It is a useful introductory check, although the exact value can vary with how the shell was started.
Display the configured login shell
echo "$SHELL"
This commonly prints the user's configured login shell, such as /bin/bash. It describes account configuration and does not always identify the process currently interpreting your commands.
List available login shells
cat /etc/shells
On many Linux systems, /etc/shells lists shell paths permitted for login. The file may contain entries such as /bin/bash, /bin/sh, or paths for other installed shells. Its exact contents vary by system.
Changing a login shell
Changing a login shell is an account-level configuration action. It should be done only when the desired shell is installed, listed as an allowed login shell, and authorized by the system's policies.
chsh -s /path/to/shell
For example, a permitted Bash path might be used in place of /path/to/shell. Do not copy a path without first checking that it exists and is listed in /etc/shells. A new login session may be required before the change is visible.
Shell troubleshooting
$SHELL does not match $0
A different shell may have been started manually inside the terminal, or the terminal application may have launched a non-login shell. Run both commands:
echo "$0"
echo "$SHELL"
The first helps identify the present session, while the second commonly reflects the configured login shell.
A desired shell is missing from /etc/shells
The shell may not be installed, or it may not have been approved as a login shell. Install or configure it according to the distribution's package and account policies. Do not set it as a login shell until it is available and allowed.
The old shell is still running after a change
The terminal session may have started before the account setting changed. Log out and log back in, or open a new terminal session, then verify the configuration with:
echo "$SHELL"
Shell terminology in other systems
Windows Command Prompt is also a command shell: it accepts typed commands and starts programs. Its commands, syntax, and environment differ from those of Linux shells. Understanding the general idea of a command interpreter transfers between systems, but a Windows command is not automatically a valid Bash command.
Summary
- A shell is a program that interprets commands and runs programs or shell-built-in operations.
- A terminal emulator or console provides a text session; the shell runs inside that session.
- The command line is the text-based method of entering commands.
- The Linux kernel manages hardware, processes, memory, filesystems, and other resources.
- Bash, C shell, and Korn shell are different shell families with different histories and syntax.
- The current shell and the account's configured login shell may not be the same.
- Shell knowledge supports later work with files, permissions, packages, scripts, and remote systems.
Continue with Linux shell concepts as a reference point before studying commands, scripting, and user-account configuration.