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
33 practiced
Given a tab-separated metrics file with columns: epoch_seconds\thost\tmetric_name\tvalue, write an awk pipeline to compute the sum of 'requests' per host for the last hour (current time obtained via date +%s). The script should accept the TSV path as input and output 'host\trequests_sum'.
EasyTechnical
44 practiced
Explain how here-documents (heredocs) work in shell scripts. Show an example that expands variables and one that prevents expansion (using <<'EOF'). Discuss use-cases like generating configuration files or embedding SQL, and explain precautions when heredoc content contains sensitive values like passwords.
MediumTechnical
73 practiced
Given a common log format line such as: 127.0.0.1 - - [2025-01-01T12:00:00Z] "GET /api/v1/users?id=1 HTTP/1.1" 200 1234write an awk script or one-liner that counts unique client IPs per request path and prints the top 10 paths by unique-IP count. Explain memory considerations and approaches for very large logs (streaming vs approximation).
HardTechnical
33 practiced
A script uses 'set -euo pipefail' and runs a pipeline 'cmd1 | cmd2 | cmd3'. Sometimes a failure in cmd2 does not cause the script to exit. Explain why that can happen in Bash and demonstrate code changes (or a pattern) so that any command in the pipeline failing will cause the script to exit. Show how to inspect the exit status of each pipeline element.
HardSystem Design
36 practiced
Design a portable 'shell-lib.sh' helper library for SRE scripts that provides logging, config parsing (KEY=VALUE style), acquire/release lock primitives, retry wrapper, and assertions. Describe the API (function names and expected behavior), how to keep it POSIX-compliant, how to test it, and distribution strategy (vendoring vs packaging).

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.