blob: 4d686874e199e7cc83a36a8b19cb4ef5381407ab [file] [log] [blame]
Michael Walsh7d68d002017-05-05 16:36:54 -05001#!/bin/bash
2
3# Template to start a simple bash program. This is designed only for the
George Keishing4f5eb802019-10-25 11:29:32 -05004# simplest of programs where all program parameters are positional, there is no
Michael Walsh7d68d002017-05-05 16:36:54 -05005# help text, etc.
6
7# Description of argument(s):
Michael Walsh410b1782019-10-22 15:56:18 -05008# parm1 Bla, bla, bla (e.g. "example data").
Michael Walsh7d68d002017-05-05 16:36:54 -05009
10
Patrick Williams90dfee32022-12-08 06:52:46 -060011function get_parms() {
Michael Walsh7d68d002017-05-05 16:36:54 -050012
Patrick Williams90dfee32022-12-08 06:52:46 -060013 # Get program parms.
Michael Walsh7d68d002017-05-05 16:36:54 -050014
Patrick Williams90dfee32022-12-08 06:52:46 -060015 parm1="${1}" ; shift
Michael Walsh7d68d002017-05-05 16:36:54 -050016
Patrick Williams90dfee32022-12-08 06:52:46 -060017 return 0
Michael Walsh7d68d002017-05-05 16:36:54 -050018
19}
Michael Walsh7d68d002017-05-05 16:36:54 -050020
21
Patrick Williams90dfee32022-12-08 06:52:46 -060022function exit_function() {
Michael Walsh7beadb22017-10-26 17:45:12 -050023
Patrick Williams90dfee32022-12-08 06:52:46 -060024 return
Michael Walsh7beadb22017-10-26 17:45:12 -050025
26}
27
Patrick Williams90dfee32022-12-08 06:52:46 -060028function validate_parms() {
Michael Walsh7d68d002017-05-05 16:36:54 -050029
Patrick Williams90dfee32022-12-08 06:52:46 -060030 # Validate program parameters.
Michael Walsh7d68d002017-05-05 16:36:54 -050031
Patrick Williams90dfee32022-12-08 06:52:46 -060032 # Your validation code here.
Michael Walsh7d68d002017-05-05 16:36:54 -050033
Patrick Williams90dfee32022-12-08 06:52:46 -060034 if [ -z "${parm1}" ] ; then
35 echo "**ERROR** You must provide..." >&2
36 return 1
37 fi
Michael Walsh7d68d002017-05-05 16:36:54 -050038
Patrick Williams90dfee32022-12-08 06:52:46 -060039 trap "exit_function $signal \$?" EXIT
Michael Walsh7beadb22017-10-26 17:45:12 -050040
Patrick Williams90dfee32022-12-08 06:52:46 -060041 return 0
Michael Walsh7d68d002017-05-05 16:36:54 -050042
43}
Michael Walsh7d68d002017-05-05 16:36:54 -050044
45
Patrick Williams90dfee32022-12-08 06:52:46 -060046function mainf() {
Michael Walsh7d68d002017-05-05 16:36:54 -050047
Patrick Williams90dfee32022-12-08 06:52:46 -060048 get_parms "$@" || return 1
Michael Walsh7d68d002017-05-05 16:36:54 -050049
Patrick Williams90dfee32022-12-08 06:52:46 -060050 validate_parms || return 1
Michael Walsh7d68d002017-05-05 16:36:54 -050051
Patrick Williams90dfee32022-12-08 06:52:46 -060052 # Your code here...
Michael Walsh7d68d002017-05-05 16:36:54 -050053
Patrick Williams90dfee32022-12-08 06:52:46 -060054 return 0
Michael Walsh7d68d002017-05-05 16:36:54 -050055
56}
Michael Walsh7d68d002017-05-05 16:36:54 -050057
58
Michael Walsh7d68d002017-05-05 16:36:54 -050059# Main
60
Patrick Williams90dfee32022-12-08 06:52:46 -060061mainf "${@}"
62rc="${?}"
63exit "${rc}"