Interview Prep/Linux/Scheduling, automation and scripting

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".

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting