File:  [Local Repository] / templates / template.sh
Revision 1.2: download - view: text, annotated - select for diffs
Mon Jan 11 16:02:23 2016 UTC (8 years, 11 months ago) by nick
Branches: MAIN
CVS tags: HEAD
Changed argument parameters and added examples.

#!/bin/sh
###############################################################################
##
## sh script template -- Script description here
##
##   Copyright Nicholas DeClario 2010
##   Nicholas DeClario <nick@demandred.dyndns.org>
##   March 2009
##   $Id: template.sh,v 1.2 2016/01/11 16:02:23 nick Exp $
##
###############################################################################

##
## Set some global variables
##
ARGS_REQ=0	## Are arguments required?
VERSION=$\Id$	## Set the version

###############################################################################
##
## help( )
## 
##    Display the basic help text
##
###############################################################################
help( ) {
        cat <<EOF
Usage:
    $0 [options]

    Options:
	   --help,?	Display the basic help menu
	   --man,m	Display the detailed man page
	   --version	Display the version

EOF

	exit 1
}   

###############################################################################
##
## man( )
##
##      Display the detailed man page
##
###############################################################################
man( ) {
        cat <<EOF | nroff -man
.TH template.sh 1 "`date`" 
.SH NAME
template.sh \- BASH template file
.SH SYNOPSIS
.B template.sh
[ name ...  ]
.SH DESCRIPTION
.I Template.sh
is a template written for BASH
.SH "SEE ALSO"
man(1)
.SH "BUGS"
.I Template.sh
is a work in progress.  Please report bugs.
.SH "COPYRIGHT NOTICE"
Copyright \(co 2006 Free Software Foundation, Inc.
.br
Copyright \(co 2010 Nicholas DeClario
.PP
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
.ig
Permission is granted to process this file through troff and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
..
.PP
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
.PP
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Foundation.
EOF
	exit 1;
}

###############################################################################
## End of shell function definitions
###############################################################################

##
##  We are going to read in our basic set of options and parse everything 
##  out.  Setting NOARGS to 1 at the top of this script will tell getOpts 
##  to call 'help' if no arguments are supplied on the command line.
##
	
## 
## If we require arguments and have none, show the help
##
[ $# -lt $ARGS_REQ ] && help;

##
## Parse through our command line arguments here
##
while [ $# -gt 0 ]
do
	arg=$1

	case $arg in
        -s|--string-var)
            shift
            string_var=$1
            ;;
        -b|--boolean-var)
            shift
            bool_var=1
            ;;
		-m|--man)
			man
			break
			;;
		-v|--version)
			echo "Version: $VERSION"
			break
			;;
		*)
			help
			break
			;;
	esac
    
    shift

done



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