shell-mastery — Builtins
Shell Builtins (bash)
List all builtins
compgen -b
compgen -b | wc -l
Critical builtins to know
type cd # cd is a shell builtin
type ls # ls is /usr/bin/ls (external)
type -a echo # echo is a shell builtin AND /usr/bin/echo
command -v awk # /usr/bin/awk (shows path for externals)
Builtins that matter in competitions
# Navigation & environment
cd, pwd, pushd, popd, dirs, export, unset, source (.), hash
# I/O
echo, printf, read, mapfile, readarray
# Flow control
if, for, while, until, case, select, break, continue, return
# Job control
bg, fg, jobs, wait, kill, disown, suspend
# String/test
test ([), [[ ]], (( ))
# History
history, fc, !!, !$, !^, !:n
# Misc power tools
eval, exec, trap, shift, set, shopt, declare, local, readonly
compgen — the discovery tool
compgen -b # builtins
compgen -k # keywords (if, for, while, case)
compgen -a # aliases
compgen -A function # defined functions
compgen -c # ALL commands (builtins + externals + aliases + functions)
compgen -c | wc -l # total command count
compgen -v # all variables
compgen -e # exported variables
compgen -f # files in current dir
compgen -d # directories in current dir
compgen -W "start stop restart" -- "st" # word completion matching "st"