InterviewStack.io LogoInterviewStack.io

Shell Scripting Basics Questions

Practical ability to write and maintain simple shell scripts using Bash and other Unix shells to automate routine system and DevOps tasks. Core skills include variable assignment and substitution, control flow with conditionals such as if and else, looping constructs such as for and while, defining and invoking functions, basic error handling and exit code checks, and logging for observability. Candidates should also be comfortable with basic file and directory operations, invoking and composing commands, and text processing using tools such as grep, sed, and awk. Emphasis is placed on scripting best practices including input validation, defensive programming, clear code organization and readability, making scripts idempotent where appropriate, and handling common edge cases when automating system administration or deployment workflows.

MediumTechnical
87 practiced
Write a Bash script that finds files under /var/log modified in the last 24 hours and compresses them with gzip. The script must correctly handle filenames with spaces, newlines, and other special characters. Provide the command(s) and explain choices between -print0/xargs -0 and -exec approaches.
MediumTechnical
81 practiced
Explain the effects and trade-offs of using 'set -euo pipefail' in Bash scripts. Provide a small example script that demonstrates each option (-e, -u, -o pipefail) and show how to safely run commands whose non-zero exit codes you want to ignore. Mention any pitfalls of set -e with compound commands or while loops.
HardTechnical
66 practiced
Write a Bash monitoring script that polls an HTTP health endpoint (URL provided as an argument) every N seconds. On failures, it should perform exponential backoff up to a maximum delay, send an alert via a webhook when consecutive failures exceed a threshold, and reset the failure count on a successful check. The script must be idempotent and avoid duplicate alerts when multiple instances run simultaneously.
MediumTechnical
77 practiced
Create a Bash script that moves files older than X days (configurable) into a quarantine directory instead of deleting them. The script should preserve ownership and permissions, support a --dry-run mode, and handle filename collisions by renaming files using a checksum suffix. Include restore instructions for quarantined files.
MediumTechnical
63 practiced
Describe reliable ways to parse JSON from a Bash script. Provide example commands using jq to extract fields, including how to handle missing fields and arrays. Also show a fallback using python -c for environments without jq and discuss pros/cons of each method.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.