Skip to content

Instantly share code, notes, and snippets.

@xphere
Created April 7, 2016 15:23
Show Gist options
  • Save xphere/4412ae37c3fcde41cc728a2c4b54dfcd to your computer and use it in GitHub Desktop.
Save xphere/4412ae37c3fcde41cc728a2c4b54dfcd 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