Interview Prep/Shell Scripting/Scenarios: writing and hardening scripts

A Bash script has grown to 900 lines, parses JSON in 40 places and has nested associative-array tricks. Your manager asks whether to keep it. What do you say?

IntermediateScenarioScenarios: writing and hardening scripts
Answer

Situation read → The script has outgrown the language. Bash is strong at orchestrating commands, weak at data structures and testable logic.

What I'd do →

  1. Identify the parts that are glue (calling kubectl, aws, rsync) and the parts that are logic (JSON transforms, decisions).
  2. Propose moving the logic to Python (or Go if a static binary helps distribution), with unit tests, while keeping a thin Bash wrapper if operators like the interface.
  3. Migrate incrementally: one subcommand at a time, both versions tested against the same fixtures.
  4. Until then, add ShellCheck and bats around the current script so the migration has a safety net.

Why → Maintenance cost and bug rate grow sharply when Bash is used as a general-purpose language.

Interview tip → Give a rule of thumb, such as "more than about 300 lines, or real data structures, means Python".

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Scenarios: writing and hardening scripts