Shell Scripting Practices
Application skill for shell learning (from the archived awesome-guidelines style capsules). Load learning note for why; capsules for probes.
Core Principle
Bash is for thin orchestration, quote aggressively, avoid subshell traps, check every mutation, and migrate before scripts become undebuggable programs.
When to Use / NOT
- Writing or reviewing
.shutilities, CI glue, or agent shell runners. - Debugging word-splitting, empty-arg, or pipe-subshell bugs.
NOT when:
- Logic exceeds ~100 lines or needs structured data, use Python/Go/etc.
- PowerShell-only environment (see awesome-guidelines PowerShell guide separately).
Workflow
- Scope, confirm shell is appropriate; bash shebang +
setfor strict modes if project uses them (shell-style-scope-and-safety.md). - Arguments,
"$@"forwarding; arrays for flag lists; quote all expansions (shell-style-quoting-and-arrays.md). - Conditionals,
[[/((/readarray; no pipe-to-while when parent needs state (shell-style-control-flow-subshells.md). - Structure, constants → functions →
main "$@";local+ split declare/assign; STDERRerr()(shell-style-structure-and-errors.md). - Verify,
shellcheckexit 0; exercise empty args, spaces in paths, and failure paths.
Red Flags
- Unquoted
$varor$@. eval, SUID bit, or string-built command lines.cmd | while readthen read parent variable.local x="$(cmd)"followed by$?check.- Script past 100 lines without migration plan.
Verification
shellcheck -x script.sh(or project wrapper) exit 0.- Manual: args with spaces, empty optional flags, failing command path.
- Capsule checklist on review.
References
awesome-guidelines/references/shell-style-learning-note.mdawesome-guidelines/references/shell-style-scope-and-safety.mdawesome-guidelines/references/shell-style-quoting-and-arrays.mdawesome-guidelines/references/shell-style-control-flow-subshells.mdawesome-guidelines/references/shell-style-structure-and-errors.md