Annotation of templates/template.sh, revision 1.2

1.1       nick        1: #!/bin/sh
                      2: ###############################################################################
                      3: ##
                      4: ## sh script template -- Script description here
                      5: ##
                      6: ##   Copyright Nicholas DeClario 2010
                      7: ##   Nicholas DeClario <nick@demandred.dyndns.org>
                      8: ##   March 2009
1.2     ! nick        9: ##   $Id: template.sh,v 1.1.1.1 2011-02-24 15:05:27 nick Exp $
1.1       nick       10: ##
                     11: ###############################################################################
                     12: 
                     13: ##
                     14: ## Set some global variables
                     15: ##
                     16: ARGS_REQ=0     ## Are arguments required?
                     17: VERSION=$\Id$  ## Set the version
                     18: 
                     19: ###############################################################################
                     20: ##
                     21: ## help( )
                     22: ## 
                     23: ##    Display the basic help text
                     24: ##
                     25: ###############################################################################
                     26: help( ) {
                     27:         cat <<EOF
                     28: Usage:
                     29:     $0 [options]
                     30: 
                     31:     Options:
                     32:           --help,?     Display the basic help menu
                     33:           --man,m      Display the detailed man page
                     34:           --version    Display the version
                     35: 
                     36: EOF
                     37: 
                     38:        exit 1
                     39: }   
                     40: 
                     41: ###############################################################################
                     42: ##
                     43: ## man( )
                     44: ##
                     45: ##      Display the detailed man page
                     46: ##
                     47: ###############################################################################
                     48: man( ) {
                     49:         cat <<EOF | nroff -man
                     50: .TH template.sh 1 "`date`" 
                     51: .SH NAME
                     52: template.sh \- BASH template file
                     53: .SH SYNOPSIS
                     54: .B template.sh
                     55: [ name ...  ]
                     56: .SH DESCRIPTION
                     57: .I Template.sh
                     58: is a template written for BASH
                     59: .SH "SEE ALSO"
                     60: man(1)
                     61: .SH "BUGS"
                     62: .I Template.sh
                     63: is a work in progress.  Please report bugs.
                     64: .SH "COPYRIGHT NOTICE"
                     65: Copyright \(co 2006 Free Software Foundation, Inc.
                     66: .br
                     67: Copyright \(co 2010 Nicholas DeClario
                     68: .PP
                     69: Permission is granted to make and distribute verbatim copies of
                     70: this manual provided the copyright notice and this permission notice
                     71: are preserved on all copies.
                     72: .ig
                     73: Permission is granted to process this file through troff and print the
                     74: results, provided the printed document carries copying permission
                     75: notice identical to this one except for the removal of this paragraph
                     76: (this paragraph not being relevant to the printed manual).
                     77: ..
                     78: .PP
                     79: Permission is granted to copy and distribute modified versions of this
                     80: manual under the conditions for verbatim copying, provided that the entire
                     81: resulting derived work is distributed under the terms of a permission
                     82: notice identical to this one.
                     83: .PP
                     84: Permission is granted to copy and distribute translations of this manual
                     85: into another language, under the above conditions for modified versions,
                     86: except that this permission notice may be stated in a translation approved
                     87: by the Foundation.
                     88: EOF
                     89:        exit 1;
                     90: }
                     91: 
                     92: ###############################################################################
                     93: ## End of shell function definitions
                     94: ###############################################################################
                     95: 
                     96: ##
                     97: ##  We are going to read in our basic set of options and parse everything 
                     98: ##  out.  Setting NOARGS to 1 at the top of this script will tell getOpts 
                     99: ##  to call 'help' if no arguments are supplied on the command line.
                    100: ##
                    101:        
                    102: ## 
                    103: ## If we require arguments and have none, show the help
                    104: ##
                    105: [ $# -lt $ARGS_REQ ] && help;
                    106: 
                    107: ##
                    108: ## Parse through our command line arguments here
                    109: ##
                    110: while [ $# -gt 0 ]
                    111: do
                    112:        arg=$1
                    113: 
                    114:        case $arg in
1.2     ! nick      115:         -s|--string-var)
        !           116:             shift
        !           117:             string_var=$1
        !           118:             ;;
        !           119:         -b|--boolean-var)
        !           120:             shift
        !           121:             bool_var=1
        !           122:             ;;
        !           123:                -m|--man)
1.1       nick      124:                        man
                    125:                        break
                    126:                        ;;
1.2     ! nick      127:                -v|--version)
1.1       nick      128:                        echo "Version: $VERSION"
                    129:                        break
                    130:                        ;;
                    131:                *)
                    132:                        help
                    133:                        break
                    134:                        ;;
                    135:        esac
1.2     ! nick      136:     
        !           137:     shift
        !           138: 
1.1       nick      139: done
                    140: 
                    141: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>