Shell
In short
A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
What is a shell in computing?
A shell is a command interpreter: it reads the commands you type, works out what you mean, and asks the operating system to carry them out. It gets its name because it is the outer layer around the kernel, the part of the system you interact with directly. Common shells include Bash, Zsh, and fish on Unix-like systems and PowerShell on Windows.
When you type a command such as ls -l, the shell splits it into a program name and arguments, searches the directories listed in the PATH environment variable for that program, and starts it as a new process. Shells also offer features that speed up work, such as variables, pipes (|) that send one command's output into another, redirection (>) that saves output to a file, command history, and tab completion. Because commands can be saved in a file and run later, the shell doubles as a scripting language for automation.
A shell is like an interpreter standing between you and the operating system. You speak in short commands, and the shell turns them into the system calls the kernel understands. Developers use shells to run build tools and Git, manage remote servers over SSH, write deployment scripts, and schedule recurring jobs.
People often confuse the shell with the terminal. The terminal, or terminal emulator, is the window that displays text and sends your keystrokes, while the shell is the program running inside it that interprets those keystrokes as commands. You can run different shells in the same terminal, and a shell can run without any terminal at all when it executes a script.
Key takeaways
- A shell interprets commands and asks the operating system to run them.
- Popular shells include Bash, Zsh, fish, and PowerShell.
- Pipes, redirection, and variables let you combine small commands into powerful ones.
- Shell scripts automate repetitive tasks such as builds, backups, and deployments.
- The terminal displays text; the shell interprets the commands.
Example
#!/usr/bin/env bash
# Variables
name="world"
echo "Hello, $name"
# Pipe: count how many .ts files are in the src folder
find src -name "*.ts" | wc -l
# Redirection: save the current date to a file
date > last-run.txtReaders ask
What is the difference between a shell and a terminal?
A terminal is the window or program that displays text and sends your keyboard input. A shell is the program running inside the terminal that reads that input and executes commands.
What is the difference between Bash and Zsh?
Both are Unix shells with very similar syntax, and most Bash scripts also run in Zsh. Zsh adds extras such as more advanced tab completion and prompt customization, and it is the default interactive shell on recent versions of macOS.
What is a shell script?
A shell script is a text file containing a series of shell commands that run in order. It is commonly used to automate tasks such as installing software, running builds, or backing up files.
Often compared
See also
- LinuxDevOps & Cloud, p. 33Linux is an open-source operating system kernel that powers most servers, cloud platforms, containers, and Android phones, usually packaged as a distribution.
- ProcessOperating Systems, p. 23A process is a running instance of a program, with its own memory space, resources, and at least one thread of execution managed by the operating system.
- KernelOperating Systems, p. 17A kernel is the core part of an operating system that manages the CPU, memory, and hardware devices and controls how programs get access to those resources.
- Environment VariableDevOps & Cloud, p. 20An environment variable is a named value set outside a program, by the operating system or runtime, that the program reads to configure its behavior.
- System CallOperating Systems, p. 31A system call is a request from a program to the operating system kernel to perform a privileged action, such as reading a file or starting a process.
- Cron JobBackend & APIs, p. 9A cron job is a command or script that runs automatically on a repeating schedule, such as every night at 2 a.m., defined by a five-field cron expression.
- BashProgramming Languages, p. 2Bash is a Unix shell and scripting language, the default on most Linux systems, used both to type commands interactively and to automate tasks with scripts.
- TerminalOperating Systems, p. 32A terminal is the program that shows a text interface, passing your keystrokes to a shell or command-line program and displaying the text it sends back.
Spotted a mistake or something missing on this page?Suggest an edit