Shell Scripting Standards¶
Status: 🟢 Active | Owner: Platform Engineering
Policy¶
Shell scripting is discouraged for complex logic. If a script exceeds 50 lines or requires conditionals beyond simple flag checks, consider rewriting in Python or Go.
Shell scripts are appropriate for:
- Build entry points that delegate to other tools.
- Simple one-shot automation in CI pipelines.
- Docker
ENTRYPOINTwrappers. - Developer setup scripts that are rarely run.
Required Header¶
Every script must start with:
set -e— exit immediately on non-zero return code.set -u— treat unset variables as an error.set -o pipefail— a pipeline fails if any command in it fails (not just the last).
ShellCheck¶
All shell scripts must pass shellcheck with no errors or warnings:
ShellCheck is enforced in CI as part of the lint stage. Install locally:
Linting Configuration¶
Add a .shellcheckrc to disable project-specific rules only where justified:
# .shellcheckrc
# Disable SC2039 in POSIX-mode scripts — we use Bash-specific features intentionally
disable=SC2039
Each disabled rule must have a comment explaining the reason.
Style Rules¶
Quote variables¶
Always double-quote variable references to prevent word splitting and glob expansion:
Use [[ ]] over [ ]¶
[[ ]] is the Bash built-in and avoids many edge cases of the POSIX [ ] test command:
Local variables in functions¶
Error messages to stderr¶
No cd without checking success¶
# ❌ Silent failure if directory doesn't exist
cd "$deploy_dir"
# ✅
cd "$deploy_dir" || error "Cannot enter $deploy_dir"
References¶
Last reviewed: 2025-Q4 | Owner: Platform Engineering