norboten · cheat sheet

A file name is any byte but slash and NUL — a backup has to believe it — cheat sheet

bash, linux-basics
# every file, whatever its name, read in the current shell
while IFS= read -r -d '' f; do
    rel=${f#"$DOCS_DIR"/}                         # quoted pattern: taken literally
    mkdir -p -- "$dest/$(dirname -- "$rel")"
    cp -p -- "$f" "$dest/$rel" || echo "could not copy $rel" >&2
done < <(find "$DOCS_DIR" -type f -print0)

printf '[%s]\n' "$name"            # see exactly what a variable holds
cmd | while …; done                # the loop's variables vanish afterwards
while …; done < <(cmd)             # they survive
cp -- "$f" "$dest"                  # names starting with - are operands
find "$dir" -type f -print0 | xargs -0 cmd      # NUL-separated all the way
[ "$failed" -eq 0 ]                # last command = the script's exit status
systemctl show unit -p Result -p ExecMainStatus