Last active
December 17, 2024 08:57
-
-
Save jRimbault/f88dcb6f3df35cb70105b53feae3da43 to your computer and use it in GitHub Desktop.
Bash script template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| #/ Script Name: template.sh | |
| #/ Author: jRimbault | |
| # Date: 2017-04-06 | |
| #/ | |
| #/ Description: | |
| #/ This is a template file meant to be used for all my future | |
| #/ bash scripting. | |
| #/ | |
| #/ Run Information: | |
| #/ I shoud write here informations about how and why to run | |
| #/ this script. | |
| #/ | |
| #/ Usage: template.sh <template> | |
| #/ | |
| #/ Options: | |
| #/ --help, -h display this help | |
| usage() | |
| { | |
| grep "^#/" "$0" | cut -c4- | |
| exit 0 | |
| } | |
| # define paramters here | |
| args() | |
| { | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| -h|--help) | |
| usage | |
| ;; | |
| esac | |
| shift | |
| done | |
| } | |
| set -euo pipefail | |
| # cleanup if necessary triggered on bad exit code | |
| cleanup() | |
| { | |
| echo | |
| } | |
| # main | |
| main() | |
| { | |
| echo | |
| } | |
| # do not execute script if it is sourced by another | |
| if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then | |
| trap cleanup SIGHUP SIGINT SIGTERM | |
| # for demo purposes, require at least 1 one arg | |
| [[ $# -lt 1 ]] && usage | |
| args "$@" | |
| main "$@" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment