Other teams want to use your script as a CLI tool. What do you add before sharing it?
BeginnerScenarioScenarios: writing and hardening scripts
Answer
Situation read → Shared tools need a stable interface, versioning and documentation.
What I'd do →
--helpwith usage, options, examples and exit codes;--versionprinting a version stamped at release.- Consistent option parsing and validation; non-zero exit codes documented.
- Dependency check at startup (
require_cmd jq curl aws) with install hints. - A README, a CHANGELOG and semantic version tags in Git.
- Distribution: a release tarball or package with checksums, or a container image; never "curl from main | bash".
- CI with ShellCheck,
shfmtand bats.
Why → Without versioning, a change you make for your team silently breaks theirs.
Interview tip → Mention keeping backward compatibility for flags, or deprecating them with a warning first.
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