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 →
- Add ShellCheck to CI for changed files only first:
git diff --name-only --diff-filter=ACM origin/main -- '*.sh' | xargs -r shellcheck -x - Fix the error-level findings everywhere immediately (
shellcheck -S error), since those are real bugs. - Commit a
.shellcheckrcwith agreed settings (source-path=SCRIPTDIR,external-sources=true). - Fix warnings script by script, starting with anything run as root or in production paths.
- Allow inline disables only with a reason comment, and review them in PRs.
- 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.
More on Scenarios: writing and hardening scripts
You inherit a 600-line `deploy.sh` with no error handling. It "sometimes half-deploys". Where do you start?IntermediateA script with `#!/bin/sh` works on CentOS but fails on Ubuntu with `Syntax error: "(" unexpected`. What is going on and what do you do?BeginnerYou need a deploy script that humans and CI both call with `--env`, `--version` and `--dry-run`. How do you design its interface?BeginnerA maintenance script must run as the `deploy` user, never as root, because files it creates must be owned by `deploy`. How do you enforce that?BeginnerTen scripts in a repo each copy-paste their own `log`, `die`, retry and config loading. How do you fix this?IntermediateA script is run both by engineers and by cron. Cron logs are full of colour codes and the script sometimes hangs waiting for input. Fix it.Beginner