Skip to content

(MIRRORED FROM GITLAB) Ready-to-use bash shell script templates at your fingertips!

Notifications You must be signed in to change notification settings

the-common/bash-script-templates

Repository files navigation

The common GNU Bash shell script templates

Ready-to-use bash shell script templates at your fingertips!

https://gitlab.com/the-common/bash-script-templates
The GitLab CI pipeline status badge of the project's main branch GitHub Actions workflow status badge pre-commit enabled badge REUSE Specification compliance badge

Flavors

This product provides several flavors of the Bash script template to satisfy different needs:

The considered to be the bare-minimum for bash scripting:

  • Shebang/Hashbang file header
  • Script description and copyright declaration header
  • Defensive interpreter behavior settings

Inherited from the BARE-MINIMUM flavor, but with the following additions:

  • Runtime dependency detection(check whether all the required commands are available from the command search PATHs
  • The following convenience variable definitions:
    • script: The absolute path of the shell script
    • script_dir: The absolute path of the directory that contains the shell script
    • script_filename: The full filename of the shell script
    • script_name: The name of the shellscript, excluding the filename suffixes
    • script_basecommand: The base command(without arguments) when running the script
    • script_args: An array containing all the command-line arguments when running the script

Inherited from the BASIC flavor, but with the following additions:

  • The introduction of the init function, which enables the moving of the program's main logic to the start of the script file, increases readability.
  • A new trap_err function has being implemented to handle the ERR trap so one can immediately recognize that an error has occurred when the errexit interpreter behavior is triggered.

References

Licensing

Unless otherwise noted(individual file's header/REUSE DEP5), this product is licensed under the 4.0 International version of the Creative Commons Attribution-ShareAlike license, or any of its recent versions you would prefer, with an exception that the template is actually being used in a different kind of product(i.e. not a template), in that case feel free to use any license you prefer(an attribution to our project would be appreciated).

This work complies to the REUSE Specification, refer REUSE - Make licensing easy for everyone for info regarding the licensing of this product.