UsiScript
#!/bin/bash # ------------------------------------------------------------------ ## Source = https://github.com/RenatGilmanov/shell-script-template/blob/master/getopts/template-getopts.sh ## Original author = RenatGilmanov ## ## Description ## This template include an example of the getops loop ## ## # [Author] Title # Description # ------------------------------------------------------------------ SUBJECT=some-unique-id VERSION=0.1.0 USAGE="Usage: command -hv -a arg" # --- Option processing -------------------------------------------- if [ $# == 0 ] ; then echo $USAGE exit 1; fi while getopts ":vh" optname do case "$optname" in "a") varARG1="$OPTARG" ;; "v") echo "Version $VERSION" exit 0; ;; "h") echo $USAGE exit 0; ;; "?") echo "Unknown option $OPTARG" exit 0; ;; ":") echo "No argument value for option $OPTARG" exit 0; ;; *) echo "Unknown error while processing options" exit 0; ;; esac done ################### # Check arguments #If the argument is empty if [ "$varARG1" = "" ]; then echo "No argument given" exit 1 # Or ask for input #echo "Enter the value =" #read varARG1 fi # ----------------------------------------------------------------- # Check / put a lock file LOCK_FILE=/tmp/${SUBJECT}.lock if [ -f "$LOCK_FILE" ]; then echo "Script is already running" exit fi # ----------------------------------------------------------------- trap "rm -f $LOCK_FILE" EXIT touch $LOCK_FILE # ----------------------------------------------------------------- # SCRIPT LOGIC GOES HERE # -----------------------------------------------------------------