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.

HardTechnical
46 practiced
Implement a Bash script 'parallel_copy.sh' that copies files from a source directory to a destination using N parallel workers, preserves file metadata, handles filenames containing spaces or newlines, resumes partially copied files, and limits concurrency to avoid saturating disk I/O. Provide the worker-pool implementation and describe how resume logic is achieved.
MediumTechnical
33 practiced
Write a robust Bash health-check script 'wait_for_service.sh' that attempts to connect to localhost:8080 up to 10 times using exponential backoff (starting at 1s), uses a per-attempt timeout, and exits non-zero if the service never returns a healthy HTTP response. The script should print progress and be safe to use from init scripts or containers as a readiness probe.
HardSystem Design
37 practiced
Design a node-local Bash monitoring script that runs on each member of a cluster and should send an alert only once when the cluster state is unhealthy (for example when a majority of nodes report failure). The design must be resilient to network partitions and node restarts and must avoid duplicate alerts. Outline the architecture, external state needed, and provide key pseudocode showing leader election or deduplication logic.
EasyTechnical
74 practiced
Write a single-line command (GNU utilities allowed) that finds all regular files under '/var/log' modified in the last 7 days and prints each full path and its size in bytes, safely handling filenames that contain spaces or newlines. Explain choices you make to handle special characters in filenames.
HardTechnical
37 practiced
Background jobs and asynchronous subshells sometimes fail silently even when 'set -e' is used. Explain why this happens and implement a robust Bash pattern that launches multiple background tasks, captures each task's exit status, and causes the main script to fail if any background task fails. Explain edge cases such as a failing task while others are still running and how to abort remaining work.

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.