InterviewStack.io LogoInterviewStack.io

Bash and Shell Scripting Questions

Covers proficiency in writing reliable Bash and POSIX shell scripts to automate common Linux system administration and operational tasks. Topics include shell syntax, variables, parameter expansion, arrays, control flow such as conditionals and loops, functions and modular script design, input and output redirection and pipes, and use of core Unix utilities for text processing such as grep, sed, and awk. Emphasizes defensive and maintainable scripting practices including error handling, exit codes, trap usage, logging, input validation, command substitution, process and job management, debugging techniques, performance considerations, and secure handling of file and process permissions. Typical use cases include service management, backups, log parsing and rotation, user provisioning, monitoring checks, and small operational tooling.

MediumTechnical
40 practiced
Explain traps in shell scripting. Provide example usages: a trap on EXIT to clean up temporary resources even when the script exits early under 'set -e', a trap on SIGINT to perform graceful shutdown, and an ERR trap to log the command that failed. Discuss limitations of traps across shells and in subshells.
EasyTechnical
43 practiced
Explain how exit codes work in shell scripts. How should a function indicate failure or success, and how should the calling code inspect and react to those exit codes? Provide a short function example that returns 42 in a specific error case and show how the caller handles that code.
MediumTechnical
33 practiced
Describe best practices for safely editing files in-place (for example config files) using sed or awk inside scripts. Provide a robust pattern that preserves file permissions and ownership, avoids data loss if the script is interrupted, and handles systems where 'sed -i' syntax differs between GNU and BSD variants.
HardTechnical
34 practiced
Write a performant, memory-efficient Bash pipeline or script that scans a 10GB newline-delimited JSON log file, extracts the top-level string field 'user_id' from each JSON object, counts the number of unique user_ids, and tolerates malformed JSON lines by skipping them while printing a warning to stderr. Use only standard Unix utilities commonly available on Linux and explain optimizations you made for performance and low memory usage.
EasyTechnical
47 practiced
Describe what the shell options 'set -euo pipefail' do in Bash scripts. For each option (-e, -u, and -o pipefail) explain its behavior, typical use in defensive scripting, and common caveats including interactions with pipelines, subshells, command lists, and conditional tests. Suggest safer patterns to use alongside these options.

Unlock Full Question Bank

Get access to hundreds of Bash and Shell Scripting interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.