[{"data":1,"prerenderedAt":917},["ShallowReactive",2],{"page-\u002Fbash":3},{"id":4,"title":5,"body":6,"description":910,"extension":911,"meta":912,"navigation":785,"path":913,"seo":914,"stem":915,"__hash__":916},"content\u002Fbash\u002Findex.md","Bash — Engineering Deep-Dive: Internals, Patterns & Production Systems",{"type":7,"value":8,"toc":893},"minimark",[9,14,18,23,58,62,116,120,125,311,315,490,494,636,640,644,655,659,662,666,680,684,690,694,737,741,889],[10,11,13],"h1",{"id":12},"bash-engineering-deep-dive","🐚 Bash — Engineering Deep-Dive",[15,16,17],"p",{},"A code-first, engineering-grade Bash curriculum. Each chapter is a deep-dive reference — minimal prose, maximum annotated production code, anti-patterns with fixes, edge cases, and under-the-hood commentary. Designed for mid-level developers moving to senior roles who learn through rigorous, real-world code.",[19,20,22],"h2",{"id":21},"how-to-use-this-reference","How to Use This Reference",[24,25,26,34,40,46,52],"ol",{},[27,28,29,33],"li",{},[30,31,32],"strong",{},"Read sequentially"," for a structured path (01 → 15).",[27,35,36,39],{},[30,37,38],{},"Jump to a chapter"," as a reference when you hit a concept in the wild.",[27,41,42,45],{},[30,43,44],{},"Run the examples"," — the terminal is your REPL.",[27,47,48,51],{},[30,49,50],{},"Use ShellCheck"," on every script you write.",[27,53,54,57],{},[30,55,56],{},"Study the anti-patterns"," — the \"❌ NAIVE → ✅ CORRECT\" pairs are the core of this curriculum.",[19,59,61],{"id":60},"prerequisites","Prerequisites",[63,64,65,68,84,106],"ul",{},[27,66,67],{},"A Unix-like system (Linux, macOS, or WSL on Windows).",[27,69,70,71,75,76,79,80,83],{},"Bash 4+ recommended (associative arrays, ",[72,73,74],"code",{},"mapfile",", ",[72,77,78],{},"${var^^}"," case conversion). macOS ships 3.2 — install Bash 5 via ",[72,81,82],{},"brew install bash",".",[27,85,86,87,75,90,75,93,75,96,75,99,75,102,105],{},"Command-line familiarity (",[72,88,89],{},"ls",[72,91,92],{},"cd",[72,94,95],{},"cat",[72,97,98],{},"grep",[72,100,101],{},"sed",[72,103,104],{},"awk",").",[27,107,108,109,112,113,105],{},"ShellCheck installed (",[72,110,111],{},"brew install shellcheck"," or ",[72,114,115],{},"apt install shellcheck",[19,117,119],{"id":118},"curriculum","Curriculum",[121,122,124],"h3",{"id":123},"part-i-shell-internals","Part I — Shell Internals",[126,127,128,144],"table",{},[129,130,131],"thead",{},[132,133,134,138,141],"tr",{},[135,136,137],"th",{},"#",[135,139,140],{},"Topic",[135,142,143],{},"What You'll Master",[145,146,147,183,205,243,272],"tbody",{},[132,148,149,153,160],{},[150,151,152],"td",{},"01",[150,154,155],{},[156,157,159],"a",{"href":158},"\u002Fbash\u002F01-introduction-and-setup","Introduction & Setup",[150,161,162,163,166,167,170,171,174,175,178,179,182],{},"Shebang mechanics (",[72,164,165],{},"execve","\u002FBINPRM_BUF_SIZE), ",[72,168,169],{},"set -euo pipefail"," internals, ",[72,172,173],{},"set -e"," exceptions, production script skeleton, ",[72,176,177],{},"trap ERR","\u002F",[72,180,181],{},"trap EXIT",", CRLF detection.",[132,184,185,188,194],{},[150,186,187],{},"02",[150,189,190],{},[156,191,193],{"href":192},"\u002Fbash\u002F02-variables-and-data-types","Variables & Data Types",[150,195,196,197,200,201,204],{},"Expansion pipeline order (brace → tilde → param → arith → cmd → process → split → glob), word-splitting internals, IFS semantics, ",[72,198,199],{},"declare"," attributes, ",[72,202,203],{},"${!var}"," indirect expansion.",[132,206,207,210,216],{},[150,208,209],{},"03",[150,211,212],{},[156,213,215],{"href":214},"\u002Fbash\u002F03-operators-and-expansions","Operators & Expansions",[150,217,218,221,222,225,226,229,230,233,234,178,237,178,240,105],{},[72,219,220],{},"((...))"," exit status quirk, ",[72,223,224],{},"[[]]"," vs ",[72,227,228],{},"[]"," mechanics, ",[72,231,232],{},"BASH_REMATCH"," capture groups, process substitution fds, glob mechanics (",[72,235,236],{},"nullglob",[72,238,239],{},"failglob",[72,241,242],{},"extglob",[132,244,245,248,254],{},[150,246,247],{},"04",[150,249,250],{},[156,251,253],{"href":252},"\u002Fbash\u002F04-control-flow","Control Flow",[150,255,256,257,260,261,264,265,178,268,271],{},"Exit status as control flow, ",[72,258,259],{},"while IFS= read -r"," internals, pipe-into-while subshell trap, ",[72,262,263],{},"case"," glob dispatch, ",[72,266,267],{},";;&",[72,269,270],{},";&"," fall-through, retry-with-backoff pattern.",[132,273,274,277,283],{},[150,275,276],{},"05",[150,278,279],{},[156,280,282],{"href":281},"\u002Fbash\u002F05-functions-and-scope","Functions & Scope",[150,284,285,286,178,289,178,292,295,296,299,300,302,303,306,307,310],{},"Dynamic scoping internals (",[72,287,288],{},"FUNCNAME",[72,290,291],{},"BASH_SOURCE",[72,293,294],{},"BASH_LINENO","), ",[72,297,298],{},"local"," masks ",[72,301,173],{},", nameref (",[72,304,305],{},"local -n",") mechanics, signal traps for graceful shutdown, ",[72,308,309],{},"export -f"," for child processes.",[121,312,314],{"id":313},"part-ii-core-systems","Part II — Core Systems",[126,316,317,327],{},[129,318,319],{},[132,320,321,323,325],{},[135,322,137],{},[135,324,140],{},[135,326,143],{},[145,328,329,356,388,432,457],{},[132,330,331,334,340],{},[150,332,333],{},"06",[150,335,336],{},[156,337,339],{"href":338},"\u002Fbash\u002F06-text-processing","Text Processing",[150,341,342,344,345,348,349,351,352,355],{},[72,343,98],{}," BRE\u002FERE\u002FPCRE modes, ",[72,346,347],{},"sed -i"," GNU vs BSD breakage, ",[72,350,104],{}," as a mini language (BEGIN\u002FEND, associative arrays), pipeline composition for log analysis, ",[72,353,354],{},"LC_ALL=C"," determinism.",[132,357,358,361,367],{},[150,359,360],{},"07",[150,362,363],{},[156,364,366],{"href":365},"\u002Fbash\u002F07-file-system-and-io","File System & I\u002FO",[150,368,369,370,373,374,75,377,380,381,384,385,105],{},"File descriptor mechanics (fd 0-9), redirection order semantics, ",[72,371,372],{},"find -print0"," + ",[72,375,376],{},"read -d ''",[72,378,379],{},"mktemp"," race-free patterns, ",[72,382,383],{},"flock"," locking, atomic writes (temp + ",[72,386,387],{},"mv",[132,389,390,393,399],{},[150,391,392],{},"08",[150,394,395],{},[156,396,398],{"href":397},"\u002Fbash\u002F08-processes-and-signals","Processes & Signals",[150,400,401,178,404,229,407,410,411,414,415,418,419,422,423,178,426,178,429,83],{},[72,402,403],{},"$!",[72,405,406],{},"wait",[72,408,409],{},"wait -n"," job pools, signal dispatch table, ",[72,412,413],{},"trap"," for graceful shutdown, ",[72,416,417],{},"timeout"," enforcement, ",[72,420,421],{},"xargs -P"," parallelism, ",[72,424,425],{},"nohup",[72,427,428],{},"disown",[72,430,431],{},"setsid",[132,433,434,437,443],{},[150,435,436],{},"09",[150,438,439],{},[156,440,442],{"href":441},"\u002Fbash\u002F09-arrays","Arrays",[150,444,445,446,225,449,452,453,456],{},"Indexed vs associative internals, ",[72,447,448],{},"[@]",[72,450,451],{},"[*]"," word semantics, sparse arrays, ",[72,454,455],{},"mapfile -d ''"," for null-delimited I\u002FO, nameref array passing, CSV processing.",[132,458,459,462,468],{},[150,460,461],{},"10",[150,463,464],{},[156,465,467],{"href":466},"\u002Fbash\u002F10-string-manipulation","String Manipulation",[150,469,470,471,178,473,178,476,178,479,482,483,485,486,489],{},"Parameter expansion operator table, ",[72,472,137],{},[72,474,475],{},"##",[72,477,478],{},"%",[72,480,481],{},"%%"," shortest\u002Flongest semantics, ",[72,484,232],{}," capture groups, ",[72,487,488],{},"printf -v"," (no subprocess), regex ERE vs PCRE.",[121,491,493],{"id":492},"part-iii-production","Part III — Production",[126,495,496,506],{},[129,497,498],{},[132,499,500,502,504],{},[135,501,137],{},[135,503,140],{},[135,505,143],{},[145,507,508,532,557,589,622],{},[132,509,510,513,519],{},[150,511,512],{},"11",[150,514,515],{},[156,516,518],{"href":517},"\u002Fbash\u002F11-command-line-arguments","Command-Line Arguments",[150,520,521,524,525,528,529,105],{},[72,522,523],{},"getopts"," state machine (OPTIND\u002FOPTARG), manual long-option parsing, ",[72,526,527],{},"--flag=value"," extraction, subcommand dispatch, stdin detection (",[72,530,531],{},"[[ -t 0 ]]",[132,533,534,537,543],{},[150,535,536],{},"12",[150,538,539],{},[156,540,542],{"href":541},"\u002Fbash\u002F12-debugging-and-error-handling","Debugging & Error Handling",[150,544,545,547,548,550,551,75,554,556],{},[72,546,173],{}," full exception model, ",[72,549,298],{}," masking, ",[72,552,553],{},"inherit_errexit",[72,555,177],{}," call-stack logging, exit code conventions (128+N), structured logging, dry-run pattern.",[132,558,559,562,568],{},[150,560,561],{},"13",[150,563,564],{},[156,565,567],{"href":566},"\u002Fbash\u002F13-best-practices","Best Practices",[150,569,570,571,574,575,578,579,178,582,584,585,588],{},"Production script architecture (",[72,572,573],{},"main"," pattern, ",[72,576,577],{},"BASH_SOURCE[0]"," + symlink resolution), library sourcing with guards, ",[72,580,581],{},"readonly",[72,583,298],{}," hygiene, ",[72,586,587],{},"eval"," avoidance, idempotent design.",[132,590,591,594,600],{},[150,592,593],{},"14",[150,595,596],{},[156,597,599],{"href":598},"\u002Fbash\u002F14-testing","Testing",[150,601,602,605,606,178,609,178,612,229,615,618,619,621],{},[72,603,604],{},"bats"," test structure, ",[72,607,608],{},"run",[72,610,611],{},"$status",[72,613,614],{},"$output",[72,616,617],{},"bats-assert"," assertions, function mocking with ",[72,620,309],{},", parameterized tests, CI integration.",[132,623,624,627,633],{},[150,625,626],{},"15",[150,628,629],{},[156,630,632],{"href":631},"\u002Fbash\u002F15-exercises-and-projects","Exercises & Projects",[150,634,635],{},"7 production projects: backup with retention, log analyzer, pre-commit hook, process supervisor with backoff, parallel image resizer, dotfile manager, capstone deployment script.",[19,637,639],{"id":638},"learning-path-suggestions","Learning Path Suggestions",[121,641,643],{"id":642},"if-youre-a-developer-using-bash-for-cicd","If you're a developer using Bash for CI\u002FCD",[15,645,646,647,649,650,75,652,654],{},"Read 01 (strict mode skeleton), 06 (log analysis pipelines), 07 (file I\u002FO, ",[72,648,372],{},"), 08 (processes, ",[72,651,417],{},[72,653,406],{},"), 12 (error handling architecture), 15 (deployment capstone).",[121,656,658],{"id":657},"if-youre-a-sysadmin","If you're a sysadmin",[15,660,661],{},"Read 06 (text tools for log parsing), 07 (file system, permissions, locking), 08 (processes, signals, graceful shutdown), 11 (CLI parsing), 13 (production script architecture), 15 (backup, supervisor, deploy).",[121,663,665],{"id":664},"if-you-know-bash-but-scripts-keep-breaking","If you know Bash but scripts keep breaking",[15,667,668,669,671,672,299,674,676,677,679],{},"Read 01 (",[72,670,169],{}," internals — why your script silently fails), 02 (quoting\u002FIFS\u002Fword-splitting — the #1 bug source), 05 (",[72,673,298],{},[72,675,173],{}," — the #2 bug source), 12 (error handling, ",[72,678,177],{},"), 13 (production architecture).",[121,681,683],{"id":682},"if-you-want-to-write-testable-maintainable-bash","If you want to write testable, maintainable Bash",[15,685,686,687,689],{},"Read 13 (script architecture, ",[72,688,573],{}," pattern, library sourcing), 14 (bats testing, mocking), 15 (production projects with tests), then apply the checklist at the end of chapter 15.",[19,691,693],{"id":692},"companion-resources","Companion Resources",[63,695,696,705,713,721,729],{},[27,697,698,704],{},[156,699,703],{"href":700,"rel":701},"https:\u002F\u002Fwww.gnu.org\u002Fsoftware\u002Fbash\u002Fmanual\u002F",[702],"nofollow","GNU Bash Manual"," — the definitive reference.",[27,706,707,712],{},[156,708,711],{"href":709,"rel":710},"https:\u002F\u002Fwww.shellcheck.net",[702],"ShellCheck"," — the Bash linter. Install locally for real-time linting.",[27,714,715,720],{},[156,716,719],{"href":717,"rel":718},"https:\u002F\u002Fwiki.bash-hackers.org",[702],"Bash Hackers Wiki"," — idioms and gotchas.",[27,722,723,728],{},[156,724,727],{"href":725,"rel":726},"https:\u002F\u002Fgithub.com\u002Fdylanaraps\u002Fpure-bash-bible",[702],"Pure Bash Bible"," — Bash-only replacements for external tools.",[27,730,731,736],{},[156,732,735],{"href":733,"rel":734},"https:\u002F\u002Fexplainshell.com",[702],"explainshell.com"," — paste a command, see what each part does.",[19,738,740],{"id":739},"tooling","Tooling",[742,743,745],"code-wrapper",{"language":744},"bash",[746,747,751],"pre",{"className":748,"code":749,"language":744,"meta":750,"style":750},"language-bash shiki shiki-themes github-light github-dark","# VS Code extensions:\n# - \"ShellCheck\" (timonwong.shellcheck) — linting\n# - \"Bash IDE\" (mads-hartmann.bash-ide) — language server\n# - \"Shell-format\" (foxundermoon.shell-format) — formatter\n\n# Install ShellCheck:\nbrew install shellcheck           # macOS\napt install shellcheck            # Debian\u002FUbuntu\n\n# Install bats-core (testing):\nbrew install bats-core            # macOS\nnpm install -g bats               # npm\n\n# Install GNU coreutils (macOS — for gcp, gmv, gsed, etc.):\nbrew install coreutils gnu-sed\n","",[72,752,753,762,768,774,780,787,793,810,823,828,834,847,865,870,876],{"__ignoreMap":750},[754,755,758],"span",{"class":756,"line":757},"line",1,[754,759,761],{"class":760},"sdCPZ","# VS Code extensions:\n",[754,763,765],{"class":756,"line":764},2,[754,766,767],{"class":760},"# - \"ShellCheck\" (timonwong.shellcheck) — linting\n",[754,769,771],{"class":756,"line":770},3,[754,772,773],{"class":760},"# - \"Bash IDE\" (mads-hartmann.bash-ide) — language server\n",[754,775,777],{"class":756,"line":776},4,[754,778,779],{"class":760},"# - \"Shell-format\" (foxundermoon.shell-format) — formatter\n",[754,781,783],{"class":756,"line":782},5,[754,784,786],{"emptyLinePlaceholder":785},true,"\n",[754,788,790],{"class":756,"line":789},6,[754,791,792],{"class":760},"# Install ShellCheck:\n",[754,794,796,800,804,807],{"class":756,"line":795},7,[754,797,799],{"class":798},"sIsaT","brew",[754,801,803],{"class":802},"sJ6F3"," install",[754,805,806],{"class":802}," shellcheck",[754,808,809],{"class":760},"           # macOS\n",[754,811,813,816,818,820],{"class":756,"line":812},8,[754,814,815],{"class":798},"apt",[754,817,803],{"class":802},[754,819,806],{"class":802},[754,821,822],{"class":760},"            # Debian\u002FUbuntu\n",[754,824,826],{"class":756,"line":825},9,[754,827,786],{"emptyLinePlaceholder":785},[754,829,831],{"class":756,"line":830},10,[754,832,833],{"class":760},"# Install bats-core (testing):\n",[754,835,837,839,841,844],{"class":756,"line":836},11,[754,838,799],{"class":798},[754,840,803],{"class":802},[754,842,843],{"class":802}," bats-core",[754,845,846],{"class":760},"            # macOS\n",[754,848,850,853,855,859,862],{"class":756,"line":849},12,[754,851,852],{"class":798},"npm",[754,854,803],{"class":802},[754,856,858],{"class":857},"snvgF"," -g",[754,860,861],{"class":802}," bats",[754,863,864],{"class":760},"               # npm\n",[754,866,868],{"class":756,"line":867},13,[754,869,786],{"emptyLinePlaceholder":785},[754,871,873],{"class":756,"line":872},14,[754,874,875],{"class":760},"# Install GNU coreutils (macOS — for gcp, gmv, gsed, etc.):\n",[754,877,879,881,883,886],{"class":756,"line":878},15,[754,880,799],{"class":798},[754,882,803],{"class":802},[754,884,885],{"class":802}," coreutils",[754,887,888],{"class":802}," gnu-sed\n",[890,891,892],"style",{},"html pre.shiki code .sdCPZ, html code.shiki .sdCPZ{--shiki-default:#6A737D;--shiki-github-dark:#6A737D}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}",{"title":750,"searchDepth":764,"depth":764,"links":894},[895,896,897,902,908,909],{"id":21,"depth":764,"text":22},{"id":60,"depth":764,"text":61},{"id":118,"depth":764,"text":119,"children":898},[899,900,901],{"id":123,"depth":770,"text":124},{"id":313,"depth":770,"text":314},{"id":492,"depth":770,"text":493},{"id":638,"depth":764,"text":639,"children":903},[904,905,906,907],{"id":642,"depth":770,"text":643},{"id":657,"depth":770,"text":658},{"id":664,"depth":770,"text":665},{"id":682,"depth":770,"text":683},{"id":692,"depth":764,"text":693},{"id":739,"depth":764,"text":740},"A code-first, engineering-grade Bash curriculum for mid-to-senior developers. 15 chapters covering shell architecture, expansion internals, control flow mechanics, function scope, text processing pipelines, file I\u002FO, process management, arrays, string manipulation, CLI parsing, error handling architecture, production script patterns, testing, and capstone projects. Every chapter is dense with production-grade code, anti-patterns, edge cases, and under-the-hood commentary.","md",{},"\u002Fbash",{"title":5,"description":910},"bash\u002Findex","CEXfFFzbqodQT2TUF5LSj1MycqmOTiDX0KWUCI2Hyvc",1789924644819]