When Bash is the right tool
Bash excels at orchestration: connecting existing commands, passing arguments, checking results and coordinating files. It is not necessarily the best language for implementing every part of a program. Choose the simplest tool that expresses the intended behavior clearly and makes failure handling testable.
Decide by the shape of the work
Use Bash for small command-driven workflows such as assembling a report from trusted utilities. For structured JSON use jq rather than treating JSON as lines of text. Python is often clearer for nested data, reusable business rules and exception handling. Go can be appropriate for a long-running concurrent network service, typed interfaces or a standalone compiled deployment. Neither language removes the need for input validation or tests. Consider deployment dependencies, team expertise, maintenance, observability and the cost of changing requirements. A short script can call a focused program with an explicit input/output contract. Do not equate fewer lines with lower complexity.
Keep the boundary explicit
Choose a fixed command, use quoted arguments, verify its exit status and validate its output before consuming it. Structured data belongs in a structured processor; stdout is the data channel and stderr is the diagnostic channel. The three examples use fixed synthetic inputs and existing tools, not external services. They illustrate three choices: orchestration in Bash, delegating data processing, and rejecting a failed component. Check input fixture creation before processing it. The partial-result drill confirms status 7 before reporting the deliberately handled failure.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code. jq, GNU coreutils, GNU tar and flock are external dependencies for selected examples. Use only synthetic files in a private directory.
Orchestrate a fixed text report
set -o pipefailprintf '%s\n' beta alpha beta > records.txt || exit 1sort records.txt | uniq -c | awk '{print $2 ":" $1}' Expected stdout:
alpha:1beta:2Bash connects three tools; each handles a focused operation. The C locale makes ordering predictable.
Delegate nested JSON processing
printf '%s\n' '{"jobs":[{"name":"a","ok":true},{"name":"b","ok":false}]}' > jobs.json || exit 1jq -er '.jobs | map(select(.ok == true)) | .[].name' jobs.jsonExpected stdout:
ajq selects structured fields without assuming that JSON occupies one line per record.
Check a component contract
component() { printf 'partial\n'; return 7; }if result=$(component); then exit 1else rc=$? [[ $rc == 7 ]] || exit 1 printf 'component failed: %s\n' "$rc" >&2fiprintf 'no published result\n' Expected stdout:
no published resultExpected stderr:
component failed: 7A partial stdout value is not a successful result. This teaching wrapper handles the failure and continues; a production caller should propagate failure when required.
Common mistakes
Do not build a JSON parser from cut or add a new process for every trivial transformation without considering the cost. Do not assume a replacement language automatically fixes unclear contracts.
Practice
Design a report from a fixed CSV-like file and a nested JSON document. Choose a tool for each, specify input format, output and failure status, and explain when a Python or Go component would be worth maintaining.
Next: Measure shell performance