You
How do I retry a network command a few times in bash?
ChatGPT
A small loop with backoff beats reaching for a tool:
for attempt in 1 2 3 4 5; do
if curl -fsS "$url" -o "$out"; then break; fi
sleep $(( attempt * 2 ))
done
The -f is essential: without it curl exits zero on a 500 and writes the error page into your output file.
You
What is the fastest way to check whether two directories match?
ChatGPT
Checksums of the file list, not a byte-by-byte diff:
cd a && find . -type f -exec sha256sum {} + | sort -k2 > /tmp/a.txt
cd ../b && find . -type f -exec sha256sum {} + | sort -k2 > /tmp/b.txt
diff /tmp/a.txt /tmp/b.txt
This also tells you which side differs, which diff -r on large trees takes far longer to reach.
You
What should be at the top of every bash script?
ChatGPT
Three lines that turn silent breakage into loud breakage:
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
-e stops on error, -u rejects unset variables, pipefail makes a failing command inside a pipe fail the whole pipe. The last one is what catches curl ... | tar x quietly producing nothing.