gitmyhub

pure-bash-bible

Shell ★ 42k updated 2y ago ▣ archived

📖 A collection of pure bash alternatives to external processes.

A reference cookbook of Bash snippets that replace external commands like sed, awk, and grep with built-in Bash features, making shell scripts faster, more portable, and free of subprocess overhead.

ShellBashsetup: easycomplexity 1/5

The Pure Bash Bible is a reference guide and code cookbook documenting how to accomplish common programming tasks using only built-in Bash features — without calling any external commands like sed, awk, grep, cut, tr, or python.

The problem it solves is that shell scripts routinely invoke external processes for simple text manipulation: running sed to replace a string, awk to split a line, or wc to count characters. Each of these launches a separate program, which carries a small but real performance cost. In loops or frequently called scripts, this overhead adds up. Bash itself has powerful built-in features — parameter expansion, pattern matching, arithmetic — that can handle most of these tasks natively with no subprocess at all. The trouble is that these features are obscure, inconsistently documented, and easy to forget.

The Pure Bash Bible collects these patterns in one place, organized by topic: string manipulation (trimming whitespace, case conversion, splitting on delimiters, URL encoding), array operations (reversing, deduplication, random element selection), file handling (reading files into variables or arrays, extracting lines), loops, conditional expressions, arithmetic, escape sequences for terminal coloring, parameter expansion tricks, and more. Each entry is a concise, tested code snippet with a description of what it does.

You would use this repository as a reference when writing shell scripts where you want to minimize dependencies, improve portability across systems where external tools may differ (different versions of sed on macOS versus Linux, for example), or simply make scripts faster. It is also a learning resource for developers who want to understand the full depth of what Bash can do natively.

The repository is shell (Bash) with snippets linted by shellcheck. There are no dependencies — the entire point is to avoid them. A companion project called the Pure sh Bible covers the same territory using the more portable POSIX sh standard.

Where it fits