Bash Builtins, Job Control, and Shell Behavior

Core Bash builtins, shell options, history, aliases, job control, traps, and interactive-shell behavior.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Core Builtins
Inspect command resolution
type -a ls

# Show whether a name resolves to an alias, builtin, function, or executable.

Get resolved command path
command -v bash

# Print how a command would be resolved.

Show builtin help
help read

# Display builtin help text.

Create alias
alias ll='ls -lah'

# Create a shell alias.

List aliases
alias

# Print current aliases.

Remove alias
unalias ll

# Remove a shell alias.

Disable builtin temporarily
enable -n test

# Disable a builtin so external command resolution can win.

## set and shopt
List set options
set -o

# Print current shell option settings.

List shopt options
shopt

# Print optional shell behavior toggles.

Enable recursive globstar
shopt -s globstar
printf '%s
' **/*.sh

# Enable ** recursive globbing.

Enable extended globbing
shopt -s extglob
printf '%s
' !(*.md)

# Enable advanced glob patterns.

Disable pathname expansion
set -f

# Disable glob expansion.

## History and Interactive Features
Show history
history | tail

# Display recent command history.

History substitution with fc
fc -s old=new

# Re-run last command after simple substitution.

Show readline bindings
bind -P | head

# Inspect key bindings handled by readline.

Reload current shell rc
source ~/.bashrc

# Load commands from a file into current shell.

## Job Control
Run process in background
sleep 60 &

# Start a job in background.

List jobs
jobs -l

# List shell jobs with process IDs.

Bring job to foreground
fg %1

# Resume a job in foreground.

Resume stopped job in background
bg %1

# Resume a stopped job in background.

Wait for background PID
pid=$!
wait "$pid"

# Wait for a specific background process.

Disown background job
disown %1

# Remove a job from shell job table.

Send signal to job
kill -TERM %1

# Signal a shell job using jobspec.

## Signals and Traps
Handle SIGINT
trap 'echo interrupted' INT

# Run shell code when Ctrl+C triggers SIGINT.

Capture exit status in trap
trap 'status=$?; echo "exiting with $status"' EXIT

# Inspect final exit status on shell exit.

List active traps
trap -p

# Print current trap handlers.