Category
2Snippets
Bash

Bash Argument Parsing with getopts: Build CLI Scripts with Flags and Options
Quick Tip getopts is a shell builtin that parses short flags properly, including grouped ones like -vf. Here is the full pattern, including the shift everybody forgets and the `local OPTIND

Bash Script Locking: Prevent Concurrent Runs with a PID File
- Bash
- Automation
- 18 Aug 2026
- 03 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