Your team writes shell scripts that parse `ls` output. Why is that a problem and what do you suggest?
IntermediateScenarioScheduling, automation and scripting
Answer
Situation read → Filenames can have spaces, newlines and globs.
What I'd do →
# bad
for f in $(ls /data); do ...; done
# good
for f in /data/*; do [[ -e "$f" ]] || continue; ...; done
# or for recursion
find /data -type f -print0 | while IFS= read -r -d '' f; do ...; done
Why → ls output is for humans; word-splitting breaks on spaces and newlines. Globs and -print0 are safe.
Interview tip → Always quote variables: "$f".
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner