Organizing and reusing Bash code

A Final Word

Bash functions are very powerful. Sooner or later, you have to use them if you really want to get the most out of your scripting skills. However, keep in mind, not everything needs to be a function. You can find articles online asserting that "everything in shell scripts should be a function." In practice, going to such extremes is not necessary for many users. That said, here is a final tip for making all your scripts more modular and reusable: Download and try the Bash3 Boilerplate project code [3], which bundles lots of operations and settings that are useful in many kinds of scripts into a general purpose format.

Infos

  1. "Tutorials – Shell Test Conditions and Exit Codes" by Marco Fioretti, Linux Magazine, issue 222, May 2019, pp. 84-88
  2. list_cronjobs: https://stackoverflow.com/questions/134906/how-do-i-list-all-cron-jobs-for-all-users
  3. Bash3 Boilerplate project: http://bash3boilerplate.sh/

The Author

Marco Fioretti (http://mfioretti.com) is a freelance author, trainer, and researcher based in Rome, Italy, who has been working with free and open source software since 1995, and on open digital standards since 2005. Marco also is a board member of the Free Knowledge Institute (http://freeknowledge.eu).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Batsh

    Batsh kills two birds with one stone: Programs written in this language can be compiled both as Linux Bash scripts and Windows batch files.

  • Bash Tuning

    In the old days, shells were capable of little more than calling external programs and executing basic, internal commands. With all the bells and whistles in the latest versions of Bash, however, you hardly need the support of external tools.

  • Bash scripting

    A few scripting tricks will help you save time by automating common tasks.

  • Shell Download Manager

    A few lines of shell code and the Gawk scripting language make downloading files off the web a breeze.

  • Quick-and-Dirty Geotagging with a Bash Script
comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News