#1
[Image: bash-production-checklist-banner.png]

A script that works once is not automatically production-ready. Before scheduling or deploying a Bash script, make its assumptions visible and test the failure paths as carefully as the happy path.

1. Declare the intended shell
Use an appropriate shebang and run the script with the shell it was written for. Bash features may fail when a script is launched as plain sh.

2. Check syntax without executing
Code:
bash -n script.sh
This parses the script without running its commands. It catches syntax errors, but it does not prove the logic or external commands are correct.

3. Run ShellCheck
ShellCheck finds many quoting, expansion, portability, and test-expression mistakes. Review each finding instead of disabling warnings broadly.

4. Quote expansions deliberately
Unquoted variables can undergo word splitting and filename expansion. Prefer
Code:
"$value"
unless splitting or globbing is specifically intended and safely constrained.

5. Validate inputs and dependencies
Check required arguments, environment variables, files, directories, permissions, and commands before changing anything. Print a useful error and exit with a nonzero status when a requirement is missing.

6. Handle failures explicitly
Understand the exact behavior of
Code:
set -e
before relying on it. Consider
Code:
set -u
for unset variables and
Code:
set -o pipefail
so pipeline failures are not silently hidden, then test the exceptions and conditionals.

7. Use safe temporary files and cleanup
Create temporary files with a safe utility such as mktemp, set restrictive permissions when needed, and use a trap to remove temporary resources on normal exit and handled signals.

8. Keep secrets out of output
Do not print passwords, tokens, cookies, private keys, or full environment dumps. Review tracing and error logs because debug output can expose expanded values.

9. Make risky actions observable and reversible
Add a dry-run mode for changes, log what the script plans to do, check the working directory and target paths, and define rollback steps. Never build destructive paths from unchecked empty variables.

10. Test in staging with edge cases
Test empty input, spaces and special characters, missing files, unavailable dependencies, permission failures, partial pipeline failures, repeated runs, and interrupted execution before scheduling the script.

Pre-deployment record
Code:
Script version:
Bash version:
Host or container:
Syntax check:
ShellCheck result:
Required commands:
Required variables:
Dry-run result:
Failure cases tested:
Rollback plan:
Log location:
Owner:

Useful references
- GNU Bash manual
- GNU Bash: The Set Builtin
- GNU Bash: Pipelines
- ShellCheck

if this helped you, a like is appreciated — wishing you the best