#safety Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Bash Recursive Directory Walker with Predicate
Use `find -print0` + `read -d ""` to safely iterate filenames that may contain spaces, newlines, or quotes. Standard bash for-loop over `find` output breaks on these.
Bash Atomic File Write (write then rename)
Write to a temp file in the SAME directory, then `mv` to the final name. mv on the same filesystem is atomic — readers never see a half-written file.
Bash Read File Line-By-Line (the safe way)
The classic `for line in $(cat file)` is wrong — it word-splits and globbing fires on filenames. Use `while IFS= read -r line` with input redirection.
Bash Safe Bash Script Template
Start every script with the same skeleton: strict error mode (errexit, nounset, pipefail), an IFS reset, and a main() function. Catches silent failures that have lost engineers weeks of debugging.