Skip to main content
SHELL-SCRIPTING5 MIN READ

Read config from the environment, not from edits

Separate per-environment configuration from shell script code using required environment variables and safe defaults.

The move: code stays stable; config changes per run. Config is what varies Hostnames, credentials, bucket names, regions, feature flags, and deploy targets vary between environments. Hardcoding them ties the script to one context and invites risky edits. The Twelve-Factor test is useful: could this repo be made public without exposing credentials or environment-specific secrets? Required versus optional Use : "${DATABASE_URL:?set DATABASE_URL}" when a value is required. Use defaults only when the default is genuinely safe, such as LOG_LEVEL="${LOG_LEVEL:-info}". Do not default production-like targets. Make the caller choose. Why shell benefits Shell scripts often sit in cron, CI, and runbooks.…

Read the full lesson

Sign up free — one personalized lesson every day, matched to your role and goals.

Already have an account? Sign in

← Back to library
Contact us