Interview Prep/Shell Scripting/Scenarios: writing and hardening scripts

Your team decides all scripts must pass ShellCheck. The first run reports 400 findings across 60 scripts. How do you roll this out?

IntermediateScenarioScenarios: writing and hardening scripts
Answer

Situation read → Blocking CI on 400 findings stops all work; ignoring them keeps the bugs. Ratchet instead.

What I'd do →

  1. Add ShellCheck to CI for changed files only first:
    git diff --name-only --diff-filter=ACM origin/main -- '*.sh' | xargs -r shellcheck -x
    
  2. Fix the error-level findings everywhere immediately (shellcheck -S error), since those are real bugs.
  3. Commit a .shellcheckrc with agreed settings (source-path=SCRIPTDIR, external-sources=true).
  4. Fix warnings script by script, starting with anything run as root or in production paths.
  5. Allow inline disables only with a reason comment, and review them in PRs.
  6. Once clean, run it on all files and make it blocking; add a pre-commit hook.

Why → A ratchet improves quality without freezing delivery, and the riskiest scripts get fixed first.

Interview tip → Say which codes you fix first: SC2086, SC2046, SC2164 and SC2155 cause real incidents.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: writing and hardening scripts