Skip to content

Instantly share code, notes, and snippets.

@weisk
Forked from xphere/script.sh
Created April 9, 2021 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weisk/5a4a2fff9df24dced7232e3a0399b6ea to your computer and use it in GitHub Desktop.
Save weisk/5a4a2fff9df24dced7232e3a0399b6ea to your computer and use it in GitHub Desktop.
Bash script skeleton
#!/bin/bash
settings() {
SCRIPT_DIR="$(dirname "$0")"
}
main() {
request $@
settings
run
}
run() {
echo "Do something"
}
syntax() {
echo ""
echo "Command description"
echo ""
echo "Usage:"
echo " command [options] [arguments]"
echo ""
echo "Options:"
echo " -h, --help Display this help message"
}
request() {
local SYNTAX=0
while [[ $# > 1 ]]
do
case "$1" in
--help|-h)
SYNTAX=1
;;
esac
shift
done
if [[ $SYNTAX -eq 1 ]]; then
syntax && die
fi
}
die() {
builtin echo $@
exit 1
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment