Bash Interview Questions
9 questions
Bash scripting interview questions on writing shell scripts that are actually safe to run unattended — error handling, quoting pitfalls, and common footguns.
A provisioning script failed halfway through, and re-running it from the top caused errors because some resources already existed. How do you make it safely re-runnable?
IntermediateBash6 min
A script processes 10,000 files one at a time in a for loop and takes hours. Someone suggests using xargs -P to parallelize it. What are the actual trade-offs and risks of doing that?
IntermediateBash6 min
A script that processes filenames from a directory listing works fine in testing, but breaks (or silently does the wrong thing) the moment a filename has a space in it. Why, and how do you fix it?
IntermediateBash7 min
What does 'set -euo pipefail' actually do at the start of a Bash script, and why is it considered close to mandatory for production scripts?
IntermediateBash7 min
A script has 'set -e' at the top, but a failing command inside a function doesn't stop the script the way you'd expect. Why not, and how do you fix it?
AdvancedBash7 min
A deployment script creates a temporary lock file at the start, but if the script fails partway through, the lock file is left behind and blocks every future run. How would you fix this?
IntermediateBash6 min
What's the actual difference between a login shell and a non-login, non-interactive shell, and why does that distinction determine which startup files get sourced?
BeginnerBash6 min
A script needs cloud CLI credentials (like AWS/Azure/gcloud auth) that are normally provided by an interactive session's environment. How do you handle that for a cron-scheduled script?
IntermediateBashAWS7 min
A backup script runs perfectly when you execute it by hand, but fails silently every night when cron runs it. How would you debug it?
BeginnerBashLinux8 min