#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
set -o pipefail
broken_command | grep something
IFS=$'\n\t'
my file.txt - Timestamped log() function — stops you from using raw echo for output, which doesn't timestamp. When you're looking at a log file and everything just says "backup complete" with no time attached, you'll wish you had this.
- CHECK / CROSS variables — adds CHECK="✓" and CROSS="✗" at the top, which is the convention across all BashSnippets scripts. Consistent visual output in the terminal.
- Argument parser with --help and --dry-run — getopts-based. Dry run mode is something I use constantly during development to test a script's logic without actually writing/deleting/moving anything.
- Lock file — prevents duplicate runs. If you're scheduling something with cron and the job sometimes runs long, without a lock file you can end up with two instances trying to write to the same output file.
- Root check — exits cleanly with an error if the script isn't run as root, instead of failing halfway through with a permission error.
- Trap on EXIT — runs a cleanup() function on exit or interruption, which you can populate with whatever teardown logic makes sense.