title: How to write unit testable bash shell code?
body: <p>In the OOP universum, there is a lot of <a href="https://stackoverflow.com/questions/1007458/writing-unit-testable-code">information</a> on how to desgin and refactor code to make it unit testing friendly. But I wonder, how to apply/translate those principles/practices (make <a href="https://stackoverflow.com/questions/36219223/shell-script-unit-testing-how-to-mockup-a-complex-utility-program">mocking</a> easier etc.) to shell scripting, which is obviously different programming.</p>
  
  <p>I have to tackle a very huge code base; many executable and non-executable procedures, large functions, big global state, many environment variables, and everywhere (unnecessary) interprocess communication and file handling through redirection/pipelines and (unnecessary) use of external utilities.</p>
  
  <p>How to refactor shell code (or design it in the beginning) to be able to make "good" automated unit tests with a framework like bats and a mocking-plugin?</p>