Shell
The shell is the program that understands your typed commands. When you open a terminal and type ls, the shell reads that, finds the right program, runs it, and shows you the output. It also lets you chain commands together and save them as scripts. Bash is the most common shell on Linux; macOS uses Zsh by default.
A shell is a command interpreter and scripting language. It parses input, expands variables and wildcards, sets up redirections and pipes, and runs programs with fork and execve.
Common shells:
- Bash (Bourne Again Shell): default interactive shell on Ubuntu, Debian, and RHEL
- sh / dash: minimal POSIX shell. On Ubuntu
/bin/shpoints to dash, so scripts starting#!/bin/shmust avoid Bash-only syntax. - Zsh: default on macOS, popular with Oh My Zsh
- fish: friendly interactive shell, not POSIX-compatible
- PowerShell: object-based shell on Windows (also runs on Linux)
What the shell handles before your program runs:
- Variable expansion (
$HOME), command substitution ($(date)) - Globbing (
*.log), quoting rules ('single'vs"double") - Redirection (
>,2>,<) and pipes (|) - Builtins (
cd,export,alias,source) that must run inside the shell itself
Startup files: ~/.bashrc for interactive shells, ~/.profile for login shells. Aliases and PATH changes go there.
Shell vs terminal: the terminal is the window; the shell is the program running inside it.
Source: bash(1) Linux manual page
Getting to know your shell
# Which shell am I in, and what is my login shell?
$ echo $0
bash
$ echo $SHELL
/bin/bash
# Is a command a builtin, alias, or program?
$ type cd ls grep
cd is a shell builtin
ls is aliased to `ls --color=auto'
grep is /usr/bin/grep
# History search: press Ctrl+R and type part of a command
# Add an alias permanently
$ echo "alias ll='ls -alF'" >> ~/.bashrc && source ~/.bashrc Most Linux admin work happens in a shell, over SSH, on machines with no desktop. Learning Bash well pays off immediately: tab completion, Ctrl+R history search, and pipes turn long tasks into one line, and scripts turn repeated tasks into one command. When a script works for you but fails in cron or another system, the cause is often a different shell or a missing environment variable.