#!/bin/bash ############################################################################### scriptName="NAME OF THE SCRIPT" scriptAuthor="NAME OF THE AUTHOR" scriptVersion="VERSION-NUMBER" scriptDate="DATE OF LAST CHANGE" scriptUrl="PROJECT'S OR AUTHOR'S URL" scriptLicense="LICENSE IF ANY" scriptDescription=<&2 fi done if [[ $requiredOk -eq 0 ]]; then echo " Please provide those programs in order to use this script" >&2 exit 2 fi ########################### End Prerequisites Check ########################### ############################ Begin Parameter Check ############################ # Initializing needed variables. These are usually the default values for all # parameters that are not obligatory. exitStatus=0 verbose=0 # Analyze parameters for param in "$@"; do knownParam=0 #### Always set $knownParam to 1 when a parameter is found #### Example: parameter is "--of=" + the value. #### since "--of=" is 5 characters long, we check for the first 5 characters #### and if it is found use the rest of the parameter as value # # if [[ "${param:0:5}" == "--of=" ]]; then # knownParam=1 # outFile="${param:5}" # fi #### Example: This Parameter is an image resolution, this can be found by #### matching the parameter. # # if [[ "${param:0:2}" != "--" ]]; then # knownParam=1 # match=$(expr match "$param" '\([0-9]*x[0-9]*\)') # if [[ "$match" != "$param" ]]; then # echo "ERROR: RES-pramatemer format must be WIDTHxHEIGHT (e.g. '1024x768'): '$param'" >&2 # exitStatus=6 # fi # # resolutions[${#resolutions[*]}]=$param # fi #### Example of a simple parameter without value # # if [[ "${param:0:9}" == "--verbose" ]]; then # knownParam=1 # verbose=1 # fi # Check for unknown parameters # Has to be at the end of this loop if [[ $knownParam -eq 0 ]]; then echo "ERROR: Unknown Parameter '$param'" >&2 exitStatus=2 fi done ############################# End Parameter Check ############################# ############################## Begin Values Check ############################# #### Example of checking for a value # # if [[ "$outFile" == "" ]]; then # echo "ERROR: Obligatory Parameters not given" >&2 # echo " Please provide an out-file (--of) parameters" >&2 # exitStatus=1 # fi #### Example of checking for more than one value # # if [[ ${#resolutions[@]} -lt 2 ]]; then # echo "ERROR: Not enough RES-parameters given" >&2 # echo " Please provide at least two image resolutions" >&2 # exitStatus=3 # fi if [[ $exitStatus -ne 0 ]]; then ## Code for debugging parameters #echo "Parameters received:" #x=0 #while [[ "$1" != "" ]]; do # let "x = $x + 1" # echo "$x: $1" # shift #done showHelp exit $exitStatus fi ############################### End Values Check ############################## ############################# Begin Actual Script ############################# ############################## End Actual Script ############################## #### Useful code examples: # # $IFS must be set to newline so a space is not interpreted as separator for # # the files returned by the find-command # IFS=$'\n'