Bash Code Snippets
Browse code snippets written in Bash

Bash Script Locking: Prevent Concurrent Runs with a PID File
- Bash
- Automation
- 18 Aug 2026
- 04 Mins read
Quick Tip Wrap any script that must not run twice at once in a PID-file lock, and a second copy simply exits instead of corrupting your data. The Problem The Problem Cron does not c

Bash Retry Function: Automatically Retry Failing Commands with Exponential Backoff
- Devops
- Shell scripting
- 20 Jul 2026
- 05 Mins read
Quick Tip Wrap any flaky command in one reusable retry function and stop re-running red pipelines by hand. The Problem The Problem Some commands fail for reasons that have nothing to

Why printf Beats echo in Linux Scripts
- Shell scripting
- Devops
- 02 Jan 2026
- 03 Mins read
Scripting Tip A script that works on your machine can produce different output on another system. The output command is often the reason. printf behaves the same way across shells, and echo d

Essential Bash Variables for Every Script
- Shell scripting
- Devops
- 26 Dec 2025
- 08 Mins read
Overview Quick Tip You know what's worse than writing scripts? Writing scripts that break every time you move them to a different machine. Built-in Bash variables fix that. The problem wi

Per-App Shell History for Bash
- Shell scripting
- Productivity
- 18 Dec 2025
- 02 Mins read
Organize your Bash history per terminal app. Ever jumped between iTerm2, Ghostty, and VS Code's terminal only to have your command history get all mixed up? This Bash snippet keeps things clean b

Per-App Shell History for Zsh
- Shell scripting
- Productivity
- 18 Dec 2025
- 02 Mins read
Organize your shell history per terminal app. Ever jumped between iTerm2, Ghostty, and VS Code's terminal only to have your command history get all mixed up? This Zsh snippet keeps things clean b

Check S3 Bucket Existence
- Aws
- Shell scripting
- 11 Jun 2025
- 02 Mins read
Quick Tip Don't let your deployment blow up because of a missing S3 bucket. This Bash script lets you check if a bucket exists before anything fails. The Problem Missing bucket failure