None of these are clever. They just stop small mistakes from becoming big ones.
- Start every script with
set -euo pipefail. Stop on the first error, treat unset variables as bugs, and don't hide failures inside pipes. - Quote your variables.
"$file", not$file. One filename with a space in it will teach you this the hard way. - Print before you delete. Run the
findon its own first, read the list, then add-delete. - Use
trapto clean up. Temporary files get removed even when the script fails halfway. - Log with timestamps. A one-line
log()function that prints the time makes every script easier to debug later.
Bash is great glue. When a script grows past a page or needs real logic, I move it to Python.