grep -rl "bash" ./blog

Bash Shell Guides

The default shell on most Linux systems: its syntax, history, expansions, redirection, and the features worth knowing beyond running commands one at a time.

20 articles

Debugging Bash Scripts: set -x, PS4, and ShellCheck How to find out what a misbehaving shell script is actually doing: syntax checks with bash -n, tracing with set -x and a better PS4, tracing to a file, catching errors with trap, and finding bugs before they run with ShellCheck. bashrc vs bash_profile vs profile: Which File to Put Things In Login shells read one set of files, interactive shells read another, and non-interactive shells read almost nothing. That is why your PATH works in a terminal and not in cron, and why your alias vanishes over ssh. getopts Explained: Parsing Script Arguments Without Regret Reading positional parameters works until someone passes flags in a different order. getopts is built into bash and handles short options properly, getopt handles long ones, and there is a reason to avoid one of them. Shell Completion: How It Works and How to Write Your Own Why Tab knows your command options, where completion scripts live, and writing one for your own tool in bash and zsh. trap and Signal Handling in Shell Scripts Cleaning up temporary files on exit, handling Ctrl+C properly, and why EXIT is the only trap most scripts need. Customizing Your Bash Prompt with PS1 How PS1 works, why unescaped colour codes wrap your lines wrongly, showing Git branch and exit status, and when to stop hand-rolling and use Starship. Zsh vs Bash vs Fish: Choosing an Interactive Shell Bash is everywhere and scripts run on it. Zsh has the best completion. Fish is the most pleasant out of the box and is not POSIX compatible. Here is what that actually costs. Bash Quoting Explained: The Single Biggest Source of Shell Bugs Word splitting and glob expansion on unquoted variables cause more shell breakage than any other single mistake. Here is exactly what each quoting style does and when to use it. Exit Codes Explained: What $? Is Telling You Every command returns a number. Zero means success and everything else means something specific, including the codes that encode which signal killed a process. Heredocs and Process Substitution in Bash Feed multi-line text to a command without a temporary file, and present a command's output where a filename is expected. Two syntaxes that remove most of the need for temporary files in scripts. Bash Arrays and Parameter Expansion Arrays handle lists of things without word splitting bugs, and parameter expansion does substring, default, and pattern operations without launching sed. Both remove whole categories of shell mistakes. seq Command Explained: Generating Number Sequences seq prints a range of numbers, with control over step, padding, and separator. It drives loops, generates test data, and builds padded filenames in one line. basename and dirname Explained: Splitting Paths in Scripts Two small commands that take a path apart reliably. They handle the edge cases that string manipulation gets wrong, and knowing the shell alternatives is worth as much as knowing the commands. Bash Error Handling: set -euo pipefail and Why Your Script Needs It By default a bash script that fails halfway through keeps running as if nothing happened. Three options change that, and knowing exactly what each one does is the difference between safety and mystery. Bash Scripting Part 2: Conditionals, Loops, and Functions Your first script ran commands top to bottom. Real scripts make decisions, repeat work, and organize into functions. This is the control-flow layer of bash: if, test brackets, for, while, case, and functions with local variables. Bash History Explained Bash remembers every command you type, and knowing how to search, reuse, and configure that history turns repetitive typing into a handful of keystrokes. This guide covers the history command, reverse search, event expansion like !! and !n, and the variables that control what gets remembered. Environment Variables and PATH Explained Environment variables control how your shell and the programs it launches behave, and PATH is the most important one, determining which commands your system can find. This guide covers viewing, setting, and permanently persisting environment variables. Job Control: bg, fg, jobs, and nohup Explained How to run multiple tasks in a single terminal session, move commands between foreground and background, and keep a process running after you disconnect, using Bash job control and nohup. Wildcards vs Regular Expressions Explained Shell wildcards and regular expressions look similar and are constantly confused, but they are different systems used in different places. This guide explains shell globbing patterns, regex basics, and which one applies where. Writing Your First Bash Script A practical introduction to Bash scripting: the shebang line, variables, arguments, conditionals, loops, and functions, with runnable examples you can adapt for real automation tasks.