| | |

LFCA 11 ๐Ÿง The Shell โ€” What It Is and How It Works

The shell is the program you talk to when you type commands in a terminal. It reads what you type, interprets it, runs programs, and shows you the output. On Linux it’s the primary way to interact with the system โ€” every command, every script, every automation goes through it. The LFCA exam expects you to know what the shell is, how it processes a command line, the difference between a shell and a terminal, the major shells available, and why the shell remains the most powerful interface on a Linux system decades after graphical desktops arrived.

Key point: A terminal is the window; a shell is the program running inside it. The terminal displays text and passes keystrokes; the shell interprets the commands and runs programs. Most Linux systems use bash as the default shell, but zsh, fish, dash, and others exist. The shell does more than run commands โ€” it expands variables, globs filenames, pipes output between programs, redirects I/O, and provides the programming language that ties Linux together.


What a shell is

A shell is a command-line interpreter. It reads input from the user (or a script), interprets it, and runs programs on the user’s behalf.

$ echo "hello"
hello

$ ls /etc
adduser.conf  apt  bash.bashrc  ...

$ date
Mon Sep 22 14:30:00 UTC 2025

Each of those lines is a command. The shell reads it, finds the program, runs it with the given arguments, and displays the output.

What the shell does:

  • Reads input โ€” from the terminal or a script
  • Parses the command line โ€” splits it into words, operators, redirections
  • Expands โ€” variables, globs, command substitutions, arithmetic
  • Runs programs โ€” finds them in $PATH or runs built-ins
  • Manages I/O โ€” pipes, redirections, background jobs
  • Provides a language โ€” variables, conditionals, loops, functions

What the shell is not:

  • Not the terminal โ€” that’s the window or console
  • Not the kernel โ€” the shell runs in user space
  • Not the same on every system โ€” multiple shells exist
  • Not a single program โ€” it’s a category of programs

Why it’s called a “shell”: It’s the outer layer around the operating system’s kernel. Users interact with the shell; the shell talks to the kernel through system calls. The kernel does the real work โ€” the shell wraps it in a friendly interface.

The relationship:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  User                                        โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  Terminal (window)                           โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  Shell (bash, zsh, etc.)                     โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  Kernel (system calls)                       โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ–ผ                                      โ”‚
โ”‚  Hardware                                    โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Why the shell matters: It’s the interface to everything. Every command, script, cron job, CI/CD pipeline, and container entrypoint runs through a shell. Knowing the shell means knowing how to use Linux โ€” not just how to click through a desktop.

Why “shell” and not “interpreter”: Both are accurate. The shell interprets commands, but it also does more โ€” it manages jobs, handles I/O, and provides a scripting language. “Shell” captures the idea that it wraps the kernel. The term is historical, from the earliest Unix systems.


Terminal vs shell

These terms are often used interchangeably, but they’re different things.

A terminal is the interface โ€” the window or physical device that displays text and captures keystrokes.

A shell is the program running inside the terminal, interpreting commands.

Terminal emulators (modern):

TerminalPlatform
GNOME TerminalLinux/GNOME
KonsoleLinux/KDE
xtermX11
iTerm2macOS
Windows TerminalWindows
AlacrittyCross-platform
kittyCross-platform

Physical terminals: Before graphical desktops, terminals were real hardware โ€” a keyboard and screen connected to a Unix machine. The “TTY” (teletype) name survives in /dev/tty and similar paths.

Virtual consoles: On Linux, you can switch between TTY consoles with Ctrl+Alt+F1 through F7. Each runs a shell independent of the graphical session.

Terminal emulators: Programs that simulate a physical terminal inside a graphical environment. When you open a “terminal” on a modern desktop, you’re running a terminal emulator.

The flow:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Terminal emulator                           โ”‚
โ”‚  โ”€ Displays text                             โ”‚
โ”‚  โ”€ Captures keystrokes                       โ”‚
โ”‚  โ”€ Passes bytes to the shell                 โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ”‚  stdin/stdout
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Shell                                       โ”‚
โ”‚  โ”€ Reads commands                            โ”‚
โ”‚  โ”€ Interprets, expands, runs                 โ”‚
โ”‚  โ”€ Prints output back                        โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Why the distinction matters: When you change shells (chsh -s /bin/zsh), you’re changing the program that runs inside the terminal, not the terminal itself. When you open a new terminal, it launches whatever shell is configured as your default.

Why “terminal” persists: The term comes from “computer terminal” โ€” the device you used to talk to a mainframe. Even though terminals are now software, the name stuck. Some old habits die slowly in computing.


Common shells

Several shells exist, each with different features.

bash โ€” the Bourne Again Shell:

The most common Linux shell. It’s the default on most distributions and the standard for scripting.

$ echo $SHELL
/bin/bash
FeatureAvailable
POSIX-compliantโœ… (mostly)
Scriptingโœ…
Command historyโœ…
Tab completionโœ…
Job controlโœ…
Arraysโœ…
Associative arraysโœ… (bash 4+)
Default onMost distros

zsh โ€” Z Shell:

Popular as an interactive shell, especially on macOS. Extends bash with more features and better defaults.

FeatureAvailable
POSIX-compliantโœ…
Scriptingโœ…
Better autocompletionโœ…
Themes and pluginsโœ… (oh-my-zsh)
Glob qualifiersโœ…
Default onmacOS (since Catalina)

fish โ€” Friendly Interactive Shell:

Designed for interactive use with helpful defaults. Not POSIX-compliant, so scripts may not work.

FeatureAvailable
POSIX-compliantโŒ
Scriptingโœ… (fish syntax)
Autosuggestionsโœ… (built-in)
Syntax highlightingโœ…
Good defaultsโœ…

dash โ€” Debian Almquist Shell:

A minimal POSIX shell. Faster than bash for scripts, used as /bin/sh on Debian/Ubuntu.

FeatureAvailable
POSIX-compliantโœ…
Scriptingโœ… (POSIX only)
Interactive featuresโŒ minimal
Speedโœ… fast
Default for/bin/sh on Debian

sh โ€” the POSIX shell:

The standard shell interface. On most systems, /bin/sh is a symlink to dash, bash, or another shell.

$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 ... /bin/sh -> dash

Other shells:

ShellNotes
csh / tcshC-like syntax, older
kshKorn shell, powerful scripting
PowerShellMicrosoft, cross-platform now
nushellModern, structured data
elvishModern, expressive

How to check your shell:

echo $SHELL       # login shell
echo $0           # current shell
ps -p $$          # process info
cat /etc/shells   # all valid shells

How to change your shell:

chsh -s /bin/zsh

chsh changes the login shell. It takes effect on next login.

Why multiple shells exist: Different needs. Bash for compatibility, zsh for features, fish for friendliness, dash for speed. Interactive use and scripting have different requirements. The variety is a feature โ€” pick the one that fits.

Why bash is the safe default: It’s on every Linux system, POSIX-compatible enough for portable scripts, and documented everywhere. If you learn one shell, learn bash. Scripts that run on unknown systems should be bash or POSIX sh.


How the shell processes a command

Every command goes through several steps before it runs.

The pipeline:

  1. Read โ€” get the line from the user or file
  2. Tokenize โ€” split into words and operators
  3. Parse โ€” build a syntax tree (commands, pipes, redirects)
  4. Expand โ€” variables, globs, substitutions
  5. Redirect โ€” set up input/output
  6. Execute โ€” run the program(s)
  7. Wait โ€” wait for completion (unless backgrounded)
  8. Repeat โ€” read the next line

An example:

$ ls -l *.txt | grep "log" > matches.txt

The shell:

  1. Tokenizes โ€” ls, -l, *.txt, |, grep, "log", >, matches.txt
  2. Parses โ€” two commands connected by a pipe, second redirected
  3. Expands โ€” *.txt โ†’ actual files like a.txt b.txt c.txt
  4. Sets up I/O โ€” stdout of ls โ†’ stdin of grep; stdout of grep โ†’ matches.txt
  5. Runs โ€” ls first (writing to the pipe), then grep
  6. Waits โ€” for both to finish

Each step matters:

  • Tokenizing respects quotes โ€” "hello world" is one word
  • Expansion is why *.txt becomes actual filenames
  • Pipes connect programs without intermediate files
  • Redirection writes output where you choose

Where the shell looks for programs: In $PATH, a colon-separated list of directories.

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

The shell checks each directory in order. The first match runs. That’s why /usr/local/bin usually comes before /usr/bin โ€” local installs override packaged ones.

Built-ins vs external commands:

  • Built-ins โ€” commands the shell itself provides (cd, echo, pwd, alias)
  • External commands โ€” programs in $PATH (ls, grep, find)

Built-ins run faster and can change shell state (cd affects the current shell). External commands run as separate processes.

How to tell:

$ type cd
cd is a shell builtin

$ type ls
ls is /usr/bin/ls

Why understanding this matters: Shell behavior is the sum of these steps. Variable expansion happening before program execution explains why echo $VAR works. Tokenizing before expansion explains why echo "hello $USER" prints one string but echo hello $USER prints two. The processing model explains most surprises.

Why the shell is not a single program: Different shells implement the process slightly differently. POSIX defines the standard, but bash, zsh, dash, and fish each have extensions. Scripts that use sh should stick to POSIX; scripts for bash can use bash features.


Shell features

The shell provides more than command execution.

Variables:

$ name="Alice"
$ echo "Hello, $name"
Hello, Alice

Variables store values. $name expands them. They can be local, exported (visible to child processes), or environment variables.

Environment variables:

$ echo $HOME
/home/alice

$ echo $USER
alice

$ echo $PATH
/usr/local/bin:/usr/bin:/bin

Common environment variables:

VariableContains
$HOMEUser’s home directory
$USERCurrent username
$PATHDirectories to search
$PWDCurrent working directory
$SHELLLogin shell
$LANGLocale
$EDITORPreferred editor

Aliases:

$ alias ll='ls -la'
$ ll

Aliases are shortcuts for longer commands. They’re shell features, not programs.

Command history:

$ history
  1  ls
  2  cd /etc
  3  cat hosts
  ...

$ !3

history lists past commands. !N re-runs the Nth. Up arrow navigates. Ctrl+R searches.

Tab completion:

Typing part of a command and pressing Tab completes it. Filenames, commands, and (with some setup) options.

Glob patterns:

$ ls *.txt           # all .txt files
$ ls file?.log       # file1.log, fileA.log, ...
$ ls [abc]*          # files starting with a, b, or c

The shell expands globs before running the command.

Pipes and redirection:

$ ls | grep "log"             # pipe
$ ls > output.txt             # redirect stdout
$ ls >> output.txt            # append
$ ls 2> errors.txt            # redirect stderr
$ ls &> all.txt               # stdout and stderr
$ cat < input.txt             # redirect stdin

Job control:

$ long_command &              # background
$ jobs                        # list jobs
$ fg                          # bring to foreground
$ bg                          # send to background
$ Ctrl+Z                      # suspend

Command substitution:

$ echo "Today is $(date)"
Today is Mon Sep 22 ...

$ files=$(ls)

$(command) runs the command and substitutes its output.

Arithmetic:

$ echo $((5 + 3))
8

$ count=$((count + 1))

Conditionals and loops: The shell is a programming language.

if [ -f /etc/hosts ]; then
  echo "File exists"
fi

for file in *.txt; do
  echo "$file"
done

Why the shell is a language: Because it needs to express logic โ€” conditions, loops, functions. Shell scripting is programming in the shell’s language. That’s why it’s both an interface and a tool.

Why the shell is powerful despite being old: It composes. Small commands, connected by pipes, each doing one thing. ls | grep | sort | uniq -c uses four programs to produce a report. No other interface composes like that. The shell’s age is its strength โ€” decades of tools, all designed to work together.


Built-ins and external commands

The shell has two kinds of commands.

Built-ins: Commands implemented inside the shell process.

Built-inPurpose
cdChange directory
echoPrint text
pwdShow current directory
aliasDefine shortcut
exportMark variable for child processes
source / .Run a script in the current shell
setShell options
unsetRemove variable
exitExit the shell
typeShow command type
historyShow command history
jobsList background jobs
bg / fgJob control

Why some commands are built-in: They must change the shell’s own state. cd changes the current directory โ€” only the shell can do that. export marks a variable for children. alias defines a shell-level shortcut. External programs can’t change the parent shell’s state.

External commands: Programs in $PATH.

$ which ls cat grep
/usr/bin/ls
/usr/bin/cat
/usr/bin/grep

Each runs as a separate process. When it exits, its state is gone โ€” it can’t affect the parent shell.

When a name matches both:

$ type echo
echo is a shell builtin

$ which echo
/usr/bin/echo

Both exist. The shell uses the built-in. type -a echo lists all versions.

How the shell decides:

  1. Check built-ins
  2. Check aliases
  3. Check functions
  4. Check $PATH

The first match wins. Built-ins take precedence because the shell doesn’t need to spawn a process.

Why this matters for scripting: cd in a script affects the script’s shell, not the caller’s. To change the caller’s directory, you must source the script, not run it. Understanding built-in vs external explains behaviors like this.

Why the distinction persists: The shell’s state is per-process. Only the shell itself can change its own state. External commands run as children and return when done โ€” they can’t touch the parent. Built-ins exist for the cases where the shell’s state must change.


A full example

A shell session showing the concepts together.

# ============================================
# PART 1: IDENTIFY THE SHELL
# ============================================

echo $SHELL
# /bin/bash

echo $0
# -bash

cat /etc/shells
# /bin/sh
# /bin/bash
# /bin/rbash
# /bin/dash
# /usr/bin/zsh

# ============================================
# PART 2: BUILT-IN VS EXTERNAL
# ============================================

type cd
# cd is a shell builtin

type ls
# ls is /usr/bin/ls

type echo
# echo is a shell builtin

type -a echo
# echo is a shell builtin
# echo is /usr/bin/echo

# ============================================
# PART 3: VARIABLES AND EXPANSION
# ============================================

name="Alice"
echo "Hello, $name"
# Hello, Alice

echo 'Hello, $name'
# Hello, $name
# (single quotes prevent expansion)

# ============================================
# PART 4: PATH AND COMMANDS
# ============================================

echo $PATH
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

which grep
# /usr/bin/grep

# ============================================
# PART 5: GLOBS AND PIPES
# ============================================

# Create some test files
cd /tmp
touch file1.txt file2.txt file3.log

ls *.txt
# file1.txt  file2.txt

ls | sort
# file1.txt
# file2.txt
# file3.log

ls | grep txt | wc -l
# 2

# ============================================
# PART 6: REDIRECTION
# ============================================

ls /etc > /tmp/listing.txt
wc -l < /tmp/listing.txt
# (number of lines)

ls /nonexistent 2>/tmp/errors.txt
cat /tmp/errors.txt
# ls: cannot access '/nonexistent': No such file or directory

# ============================================
# PART 7: COMMAND SUBSTITUTION
# ============================================

echo "Today is $(date +%A)"
# Today is Monday

files=$(ls /tmp/*.txt)
echo "$files"
# /tmp/file1.txt /tmp/file2.txt

# ============================================
# PART 8: ALIASES
# ============================================

alias ll='ls -la'
alias
# alias ll='ls -la'

# Only in this shell
# To persist, add to ~/.bashrc

# ============================================
# PART 9: HISTORY
# ============================================

history | tail -5
# (last 5 commands)

# ============================================
# PART 10: JOB CONTROL
# ============================================

sleep 10 &
# [1] 12345

jobs
# [1]+  Running    sleep 10 &

kill %1
# terminate the job

Every part touches a different shell concept โ€” identifying the shell, built-ins vs external commands, variables, globs, pipes, redirection, substitution, aliases, history, and job control.

Why this session: It walks through the shell’s features in the order you’d use them. Identify the shell, then use variables, then compose commands with pipes and redirection, then manage jobs. Each concept builds on the previous, and each is something the LFCA exam expects.


Complete Example Session

# ============================================
# PART 1: WHAT SHELL AM I RUNNING?
# ============================================

echo $SHELL
# [ /bin/bash ]

echo $0
# [ bash ]

ps -p $$
# [   PID TTY          TIME CMD ]
# [ 12345 pts/0    00:00:00 bash ]

cat /etc/shells
# [ /bin/sh ]
# [ /bin/bash ]
# [ /bin/rbash ]
# [ /bin/dash ]
# [ /usr/bin/zsh ]

# ============================================
# PART 2: TYPE CHECKING
# ============================================

type pwd
# [ pwd is a shell builtin ]

type cat
# [ cat is /usr/bin/cat ]

type -a test
# [ test is a shell builtin ]
# [ test is /usr/bin/test ]

# ============================================
# PART 3: VARIABLES
# ============================================

greeting="Hello, World"
echo "$greeting"
# [ Hello, World ]

echo '$greeting'
# [ $greeting ]

export EDITOR=vim
echo $EDITOR
# [ vim ]

# ============================================
# PART 4: PATH
# ============================================

echo $PATH | tr ':' '\n'
# [ /usr/local/sbin ]
# [ /usr/local/bin ]
# [ /usr/sbin ]
# [ /usr/bin ]
# [ /sbin ]
# [ /bin ]

which python3
# [ /usr/bin/python3 ]

# ============================================
# PART 5: GLOBS
# ============================================

cd /tmp
touch a.txt b.txt c.log d.txt

echo *.txt
# [ a.txt b.txt d.txt ]

echo ?.txt
# [ a.txt b.txt d.txt ]

echo [ab].txt
# [ a.txt b.txt ]

# ============================================
# PART 6: PIPES
# ============================================

ls /etc | wc -l
# [ 220 ]

cat /etc/passwd | grep bash | wc -l
# [ (number of bash users) ]

ps aux | grep ssh | head -3

# ============================================
# PART 7: REDIRECTION
# ============================================

date > /tmp/now.txt
cat /tmp/now.txt

date >> /tmp/now.txt
wc -l < /tmp/now.txt
# [ 2 ]

ls /nonexistent 2> /tmp/err.txt
cat /tmp/err.txt

# ============================================
# PART 8: COMMAND SUBSTITUTION
# ============================================

uptime_seconds=$(cut -d. -f1 /proc/uptime)
echo "System has been up for $uptime_seconds seconds"

kernel=$(uname -r)
echo "Kernel: $kernel"

# ============================================
# PART 9: ALIASES AND FUNCTIONS
# ============================================

alias ll='ls -la'
alias grep='grep --color=auto'

myfunc() {
  echo "Hello from $1"
}
myfunc "test"
# [ Hello from test ]

# ============================================
# PART 10: JOB CONTROL
# ============================================

sleep 30 &
# [ [1] 54321 ]

jobs
# [ [1]+  Running    sleep 30 & ]

fg %1
# (brings sleep to foreground)
# Ctrl+Z suspends
# bg sends back to background

kill %1

# ============================================
# PART 11: BUILT-IN COMMANDS
# ============================================

cd /etc
pwd
# [ /etc ]

cd -
# [ /tmp ]

export MYVAR="test"
env | grep MYVAR

unset MYVAR
echo "$MYVAR"
# (empty)

# ============================================
# PART 12: SCRIPTING PREVIEW
# ============================================

if [ -f /etc/hosts ]; then
  echo "Hosts file exists"
fi

for f in /tmp/*.txt; do
  echo "File: $f"
done

count=0
while [ $count -lt 3 ]; do
  echo "Count: $count"
  count=$((count + 1))
done

Each section exercises a shell concept. Together they form a tour of what the shell does.


Quick Reference

Shell vs Terminal

AspectTerminalShell
What it isWindow or deviceProgram
RoleDisplay + inputInterpret + execute
ExampleGNOME Terminalbash
Changes withchshDefault config

Common Shells

ShellPathNotes
bash/bin/bashDefault on most Linux
zsh/usr/bin/zshmacOS default
fish/usr/bin/fishFriendly, not POSIX
dash/bin/dashFast, POSIX, Debian
sh/bin/shPOSIX, symlink
ksh/bin/kshKorn shell
csh/tcsh/bin/cshC-like

Identifying the Shell

CommandShows
echo $SHELLLogin shell
echo $0Current shell
ps -p $$Shell process
cat /etc/shellsValid shells
chsh -s PATHChange login shell

Command Processing Steps

StepWhat happens
1Read input
2Tokenize
3Parse
4Expand (vars, globs, subs)
5Set up redirection
6Execute
7Wait
8Repeat

Built-in vs External

AspectBuilt-inExternal
Runs inShell processSeparate process
Can change shell stateโœ…โŒ
Examplescd, echo, pwdls, grep, find
SpeedFastSlower (new process)
Check withtypewhich

Common Built-ins

Built-inPurpose
cdChange directory
pwdPrint working directory
echoPrint text
exportMark variable for export
aliasDefine shortcut
source / .Run script in current shell
setShell options
unsetRemove variable
exitExit shell
typeShow command type
historyCommand history
jobsBackground jobs
bg / fgJob control

Environment Variables

VariableContains
$HOMEHome directory
$USERUsername
$PATHSearch path
$PWDCurrent directory
$SHELLLogin shell
$LANGLocale
$EDITORPreferred editor
$PS1Prompt

Shell Features

FeatureExample
Variablesname="Alice"
Expansion$name, ${name}
Globs*.txt, file?.log
Pipesls | grep x
Redirectioncmd > file
Command substitution$(date)
Arithmetic$((5 + 3))
Aliasesalias ll='ls -la'
Functionsf() { ... }
Conditionalsif [ ... ]; then
Loopsfor x in ...; do

Redirection Operators

OperatorEffect
>Redirect stdout (overwrite)
>>Redirect stdout (append)
2>Redirect stderr
&>Both stdout and stderr
<Redirect stdin
|Pipe stdout to next
teeWrite to file and screen

Job Control

CommandAction
cmd &Run in background
jobsList jobs
fg %nForeground job
bg %nBackground job
Ctrl+ZSuspend current
Ctrl+CInterrupt current
kill %nKill job

Path-Related

CommandPurpose
pwdCurrent directory
cd DIRChange directory
cd ~Home
cd -Previous
which CMDLocation in PATH
type CMDType of command
whereis CMDBinary + docs

Globs

PatternMatches
*Any characters
?One character
[abc]a, b, or c
[a-z]Range
[!abc]Not a, b, or c
~Home directory
{a,b}a or b (brace expansion)

Special Characters

CharacterMeaning
\Escape next character
'...'Literal (no expansion)
"..."Mostly literal ($, \, backtick still work)
`...`Command substitution (legacy)
$(...)Command substitution
;Command separator
&&Run next if previous succeeds
||Run next if previous fails

Exit Codes

CodeMeaning
0Success
Non-zeroFailure
$?Last exit code
$!PID of last background job

Files Configuring the Shell

FilePurpose
~/.bashrcbash interactive config
~/.bash_profilebash login config
~/.zshrczsh config
/etc/bash.bashrcsystem bash config
/etc/profilesystem login config

Switching Shells

ActionCommand
Run a shellbash, zsh, fish
Change defaultchsh -s /bin/zsh
Run script in specific shellzsh script.sh
Force POSIX behaviorsh script.sh

Best Practices

โœ… Do This:

# Check your shell before assuming
echo $SHELL                                       # โœ…

# Use type to see if a command is built-in
type cd                                           # โœ…

# Quote variables in scripts
echo "$name"                                      # โœ…

# Use single quotes for literals
echo '$PATH'                                      # โœ…

# Prefer $(...) over backticks
echo "$(date)"                                    # โœ…

# Use built-ins when state matters
cd /etc                                           # โœ…

# Use external commands for processing
grep "pattern" file.txt                           # โœ…

# Redirect stderr when ignoring errors
command 2>/dev/null                               # โœ…

# Check exit codes in scripts
if command; then ... fi                           # โœ…

# Read your rc files
cat ~/.bashrc                                     # โœ…

โŒ Don’t Do This:

# Don't assume sh is bash
sh script.sh  # POSIX only                            # โš ๏ธ

# Don't use unquoted variables with spaces
cp $file /dest  # breaks on spaces                    # โŒ

# Don't rely on alias in scripts
alias ll='ls -la'  # won't apply in scripts           # โš ๏ธ

# Don't use cd in a script expecting to affect caller
# Scripts run in subshells                             # โŒ

# Don't ignore exit codes
rm file  # if this fails, continue anyway?            # โš ๏ธ

# Don't use backticks in new scripts
echo `date`  # use $(date)                            # โš ๏ธ

# Don't overwrite files with > accidentally
echo "x" > important.txt  # overwrites!               # โŒ

# Don't use rm without thinking
rm -rf /tmp/*  # what if /tmp/* matches more?         # โŒ

# Don't run untrusted scripts as root
sudo bash script.sh                                   # โš ๏ธ

Common Pitfalls

PitfallProblemSolution
Assuming sh = bashScript failsUse #!/bin/bash or POSIX
Unquoted $varWord splittingAlways quote
Single vs double quotesNo expansionKnow the difference
> overwritesData lossUse >> to append
Alias in scriptNot appliedUse functions or full commands
cd in scriptAffects script onlysource to affect caller
Ignoring exit codesSilent failuresCheck $?
Wrong shell interpreterSyntax errorsCheck shebang
Globs expanding unexpectedlyWrong filesQuote patterns
Path order mattersWrong binary runsCheck $PATH order

Real-World Examples

1. Check current shell

echo $SHELL

2. List available shells

cat /etc/shells

3. Change login shell

chsh -s /bin/zsh

4. Show PATH

echo $PATH

5. Find a command

which ls

6. Check if built-in

type cd

7. Show all matches

type -a echo

8. Set a variable

name="Alice"

9. Export for child processes

export EDITOR=vim

10. Use command substitution

echo "Kernel: $(uname -r)"

11. Pipe commands

ls | grep .txt

12. Redirect to file

ls /etc > listing.txt

13. Append to file

date >> log.txt

14. Redirect stderr

command 2> errors.txt

15. Discard output

command > /dev/null 2>&1

16. Background a job

long_task &

17. Check jobs

jobs

18. Create an alias

alias ll='ls -la'

19. Check exit code

echo $?

20. Read rc file

cat ~/.bashrc

Visual: User to Kernel

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  User                                        โ”‚
โ”‚  โ”€ types a command                           โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ”‚  keystrokes
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Terminal                                    โ”‚
โ”‚  โ”€ displays characters                       โ”‚
โ”‚  โ”€ captures input                            โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ”‚  bytes
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Shell                                       โ”‚
โ”‚  โ”€ parses the line                           โ”‚
โ”‚  โ”€ expands variables and globs               โ”‚
โ”‚  โ”€ sets up pipes and redirection             โ”‚
โ”‚  โ”€ runs the program                          โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ”‚  system calls
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Kernel                                      โ”‚
โ”‚  โ”€ executes the process                      โ”‚
โ”‚  โ”€ manages files, processes, hardware        โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ”‚  output
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Terminal โ†’ User                             โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Command Processing

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ ls -l *.txt | grep log > matches.txt      โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  1. Tokenize                                 โ”‚
โ”‚     ls  -l  *.txt  |  grep  log  >  matches.txtโ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  2. Parse                                    โ”‚
โ”‚     cmd1: ls -l *.txt                        โ”‚
โ”‚     cmd2: grep log                           โ”‚
โ”‚     pipe: cmd1 | cmd2                        โ”‚
โ”‚     redirect: cmd2 > matches.txt             โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  3. Expand                                   โ”‚
โ”‚     *.txt โ†’ a.txt b.txt c.txt                โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  4. Set up I/O                               โ”‚
โ”‚     ls stdout โ†’ pipe โ†’ grep stdin            โ”‚
โ”‚     grep stdout โ†’ matches.txt                โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  5. Execute                                   โ”‚
โ”‚     Run ls โ†’ write to pipe                   โ”‚
โ”‚     Run grep โ†’ read from pipe โ†’ write file   โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Built-in vs External

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Built-in (cd, echo, pwd)                    โ”‚
โ”‚                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  Shell process                         โ”‚ โ”‚
โ”‚  โ”‚  โ”€ parses command                      โ”‚ โ”‚
โ”‚  โ”‚  โ”€ runs built-in directly              โ”‚ โ”‚
โ”‚  โ”‚  โ”€ can change shell state              โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  External (ls, grep, find)                   โ”‚
โ”‚                                              โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  Shell process                         โ”‚ โ”‚
โ”‚  โ”‚  โ”€ parses command                      โ”‚ โ”‚
โ”‚  โ”‚  โ”€ forks a child process               โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚            โ”‚                                 โ”‚
โ”‚            โ–ผ                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚  Child process                         โ”‚ โ”‚
โ”‚  โ”‚  โ”€ executes ls or grep                 โ”‚ โ”‚
โ”‚  โ”‚  โ”€ can't change parent shell state     โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Common Shells

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  bash โ”€โ”€โ”€โ”€โ”€โ”€ default on most Linux           โ”‚
โ”‚  โ”€ POSIX, arrays, functions, history         โ”‚
โ”‚                                              โ”‚
โ”‚  zsh โ”€โ”€โ”€โ”€โ”€โ”€โ”€ macOS default                   โ”‚
โ”‚  โ”€ bash superset, better completion          โ”‚
โ”‚                                              โ”‚
โ”‚  fish โ”€โ”€โ”€โ”€โ”€โ”€ friendly, not POSIX             โ”‚
โ”‚  โ”€ autosuggestions, highlighting             โ”‚
โ”‚                                              โ”‚
โ”‚  dash โ”€โ”€โ”€โ”€โ”€โ”€ fast, minimal POSIX             โ”‚
โ”‚  โ”€ /bin/sh on Debian/Ubuntu                  โ”‚
โ”‚                                              โ”‚
โ”‚  sh โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ POSIX standard                  โ”‚
โ”‚  โ”€ symlink to bash, dash, or other           โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Pipes and Redirection

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ ls | grep log                             โ”‚
โ”‚                                              โ”‚
โ”‚  ls โ”€โ”€โ”€โ”€ stdout โ”€โ”€โ”€โ”€โ”                        โ”‚
โ”‚                     โ”‚                        โ”‚
โ”‚                     โ–ผ                        โ”‚
โ”‚                 [pipe]                       โ”‚
โ”‚                     โ”‚                        โ”‚
โ”‚                     โ–ผ                        โ”‚
โ”‚  grep โ”€โ”€โ”€โ”€ stdin โ”€โ”€โ”€โ”˜                        โ”‚
โ”‚       โ””โ”€โ”€โ”€โ”€ stdout โ”€โ”€โ”€โ”€โ–บ terminal            โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ ls > files.txt                            โ”‚
โ”‚                                              โ”‚
โ”‚  ls โ”€โ”€โ”€โ”€ stdout โ”€โ”€โ”€โ”€โ–บ files.txt              โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ cat < input.txt                           โ”‚
โ”‚                                              โ”‚
โ”‚  input.txt โ”€โ”€โ”€โ”€ stdin โ”€โ”€โ”€โ”€โ–บ cat              โ”‚
โ”‚                          โ””โ”€โ”€โ”€ stdout โ”€โ”€โ–บ termโ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Variable Expansion

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ name="Alice"                              โ”‚
โ”‚  $ echo "Hello, $name"                       โ”‚
โ”‚                                              โ”‚
โ”‚  Before expansion:                           โ”‚
โ”‚  echo "Hello, $name"                         โ”‚
โ”‚                                              โ”‚
โ”‚  After expansion:                            โ”‚
โ”‚  echo "Hello, Alice"                         โ”‚
โ”‚                                              โ”‚
โ”‚  Command runs with expanded argument         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Double quotes: expand $, ``, \              โ”‚
โ”‚  Single quotes: literal                      โ”‚
โ”‚                                              โ”‚
โ”‚  echo "$name"    โ†’ Hello, Alice              โ”‚
โ”‚  echo '$name'    โ†’ Hello, $name              โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: PATH Search

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ which ls                                  โ”‚
โ”‚                                              โ”‚
โ”‚  PATH=/usr/local/sbin:/usr/local/bin:        โ”‚
โ”‚       /usr/sbin:/usr/bin:/sbin:/bin          โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Search order:                               โ”‚
โ”‚                                              โ”‚
โ”‚  1. /usr/local/sbin/ls  โ†’ not found          โ”‚
โ”‚  2. /usr/local/bin/ls   โ†’ not found          โ”‚
โ”‚  3. /usr/sbin/ls        โ†’ not found          โ”‚
โ”‚  4. /usr/bin/ls         โ†’ FOUND โœ…           โ”‚
โ”‚                                              โ”‚
โ”‚  Run /usr/bin/ls                             โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Job Control

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ sleep 60 &                                โ”‚
โ”‚  [1] 12345                                   โ”‚
โ”‚                                              โ”‚
โ”‚  Background job runs, prompt returns         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ jobs                                      โ”‚
โ”‚  [1]+  Running    sleep 60 &                 โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ fg %1                                     โ”‚
โ”‚  sleep 60                                    โ”‚
โ”‚  (Ctrl+Z)                                    โ”‚
โ”‚  [1]+  Stopped    sleep 60                   โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚
                  โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  $ bg %1                                     โ”‚
โ”‚  [1]+ sleep 60 &                             โ”‚
โ”‚  (running in background again)               โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Shell Configuration Files

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  System-wide:                                โ”‚
โ”‚  โ”€ /etc/profile                              โ”‚
โ”‚  โ”€ /etc/bash.bashrc                          โ”‚
โ”‚  โ”€ /etc/profile.d/*.sh                       โ”‚
โ”‚                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  User-specific (bash):                       โ”‚
โ”‚  โ”€ ~/.bash_profile   (login shells)          โ”‚
โ”‚  โ”€ ~/.bashrc         (interactive)           โ”‚
โ”‚  โ”€ ~/.bash_logout    (on logout)             โ”‚
โ”‚                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  User-specific (zsh):                        โ”‚
โ”‚  โ”€ ~/.zshrc                                  โ”‚
โ”‚  โ”€ ~/.zprofile                               โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Decision Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Need to change something in the shell?      โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Use a built-in                     โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Need to process files or data?              โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Use external commands              โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Need to connect commands?                   โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Pipe or redirect                   โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Need it to persist across sessions?         โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Add to ~/.bashrc or ~/.zshrc       โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Need it in scripts?                         โ”‚
โ”‚       โ”‚                                      โ”‚
โ”‚       โ””โ”€โ”€ Use functions, not aliases         โ”‚
โ”‚                                              โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ConceptMeaning
ShellProgram that interprets commands
TerminalWindow or device that runs the shell
bashDefault shell on most Linux
zshFeature-rich, macOS default
fishFriendly, not POSIX
dashFast, minimal POSIX
Built-inCommand in the shell process
ExternalProgram in $PATH
VariableNamed value
ExpansionReplace $var with value
GlobPattern like *.txt
PipeConnect programs
RedirectionRoute I/O to files
Job controlBackground and foreground

Key takeaways:

  • The shell interprets commands; the terminal is the window it runs in
  • bash is the standard Linux shell; zsh, fish, and dash are alternatives
  • The shell processes a command line in stages: tokenize, parse, expand, execute
  • Built-ins run in the shell process and can change its state; external commands run as separate processes
  • Variables store values; $name expands them
  • Globs โ€” *.txt, file? โ€” expand to matching filenames
  • Pipes โ€” | โ€” connect the output of one command to the input of another
  • Redirection โ€” >, >>, <, 2> โ€” routes input and output
  • Command substitution โ€” $(cmd) โ€” inserts a command’s output
  • Job control โ€” &, jobs, fg, bg, Ctrl+Z โ€” manages background processes
  • Aliases are shortcuts; functions are scripts inside the shell
  • The shell is a programming language โ€” variables, conditionals, loops
  • ~/.bashrc and ~/.zshrc configure the shell per user
  • /etc/shells lists valid shells; chsh -s changes the login shell

Remember: The shell is the interface to Linux โ€” the program that reads your commands, interprets them, and runs them. It’s not the terminal, which is just the window. It provides variables, globs, pipes, redirection, and job control โ€” features that make command-line work powerful. bash is the standard, but zsh, fish, and dash each have strengths. Understanding what the shell does โ€” and how it processes a command โ€” is the foundation for everything else in Linux. Every script, every automation, every CI/CD pipeline runs through a shell.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!