When Bash & Shell Scripting misbehaves, the cause is usually one of a handful of familiar issues. Here is how to spot and fix them fast.
The usual suspects
- No set -euo pipefail, so failures are silently ignored
- Unquoted variables that break on spaces and globs
- Parsing ls output or using eval on untrusted input
Commands for diagnosis
shellcheck deploy.sh
shfmt -d -i 2 deploy.sh
bash -n deploy.sh # syntax check without runningPrevent the repeat
- Start every script with set -Eeuo pipefail and an ERR trap
- Quote all variable expansions; prefer [[ ]] over [ ]
- Run shellcheck and shfmt in CI
Want senior help putting Bash & Shell Scripting to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.