Bash-script-framework

From I Will Fear No Evil
Revision as of 15:47, 15 October 2021 by Chubbard (talk | contribs) (Created page with "<pre> #!/bin/bash #=============================================================================== # # FILE: FILENAME.sh # # USAGE: ./FILENAME.sh < options...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#!/bin/bash
#===============================================================================
#
#          FILE:  FILENAME.sh
# 
#         USAGE:  ./FILENAME.sh < options >
# 
#  REQUIREMENTS:  ifconfig snmptrap tr sed awk
#        AUTHOR:  Christopher S. Hubbard (), chubbard@iwillfearnoevil.com
#       COMPANY:  I Will Fear No Evil DOT com
#       VERSION:  2.0.1
#       CREATED:  02/18/2011 06:49:51 PM PST
#      REVISION:  Mary
#===============================================================================
Details
Revision starts at the letter A and goes through M
Version starts at 0.0.1 and increments when major changes happen
Requirements are what should be validated before running the script

Use function

#===  FUNCTION  ================================================================
#          NAME:  usage
#   DESCRIPTION:  how to use the !@#$ script correctly
#    PARAMETERS:  None
#       RETURNS:  stdout and exit
#===============================================================================
usage (){
cat << EOF
Usage: $0 options

Options:
-h  show this help screen
-x  enable debug mode

example:

EOF
}

Getopts framework

while getopts "hx" OPTION; do
  case ${OPTION} in
    h) usage; exit 0 ;;
    x) export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'; set -v ;set -x ;;
    *) echo "Status FATAL - Unexpected arguments given.  Try -h.  Used $@"; exit 2 ;;
  esac
done