Skip to content

Why put code into a function in shell scripts?

Putting code into functions makes it easier to manage, especially when using editors like vi. One big benefit of doing this is that I can quickly cut and paste entire functions using commands like dap in vi, which deletes a full function block. This makes it easy to move or reuse the code elsewhere.

Using functions help by:

  • Making code modular and reusable
  • Reducing the need to depend on external scripts
  • Keeping everything in one place, which simplifies maintenance