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.

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.
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.
HardSystem Design
37 practiced
Design a POSIX-compliant script 'deploy_atomic.sh' to perform an atomic deploy of a release directory into '/var/www/app' using a 'current' symlink. Requirements: create a new release directory, verify release integrity using SHA256, run pre-deploy checks, swap the 'current' symlink atomically to the new release to avoid downtime, support rollback on failure, and avoid race conditions when concurrent deploys occur. Explain your locking strategy and provide illustrative code snippets.
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.
HardTechnical
38 practiced
You inherit a 10k-line legacy Bash script running in production that has little documentation and no tests. Present a practical, low-risk plan to refactor it for maintainability and reliability. Include steps for behavior capture, adding tests (unit/integration), incremental modularization, CI integration (linting and tests), and criteria to decide whether to incrementally refactor or rewrite modules. Also recommend short-term mitigations to reduce risk while refactoring.

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.