How to create a module

Next we are taking a look at how to create a module Creating a module is easy. In general, modules are just plain shell scripts.


There are just two things to be aware of:

  1. a shebang MUST be present (e.g., #!/bin/sh, if POSIX compliant)

  2. modules should assume the function module is defined


This example module (‘Greeter’) takes one argument, the name, and writes a message containing that name to standard out. If no name is provided it writes an error message to standard error and returns error code 1:



if [ "$name" != "" ]; then
	printf 'Hello %s' "$name"
	echo "No name provided to module Greeter" >/dev/stderr
	return 1

In order, to foster cooperation and the online availability of modules, doesn’t support importing modules from filesystem. So if you want to use your module you should place it on a web-server (e.g., and load it from there:


# load
eval "$(curl -fsL "")"

# load  module greeter
module "greeter" ""

# use module greeter
greeter "Bob"

Executing that script should result in Hello Bob

Since we also acknowledge that for module developers it is an important feature to load modules from disk (which we required ourselves during the development of, we added an extra module module-local to our repository (not published yet).

Best practices

Since the strength of shell scripts is not its performance, but its compability to run on different platforms, we encurage POSIX compliance and correntness.


If you have gone the extra mile to create a POSIX compliant script you can and should use the #!/bin/sh shebang.

If you were lazy and used e.g., bash syntax, please use the modern #!/usr/bin/env bash shebang.


Modules should not set options themselves but should be able to run with the following configuration:

set -eEuo pipefail

This means abort script execution if

  • a command returned a non-zero error code outside of a condition clause (-e)
  • even in sub-shells (-E)
  • and pipes (-o pipefail)
  • or if an unbound/undefined variable is used (-u)


Another great way to help you writing awesome scripts is the tool shellcheck.

Publishing on

If you have followed the best practices and are willing to donate your script to the public domain, please feel free to create a pull request via Github.