Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Template to start a simple bash program. This is designed only for the |
Gunnar Mills | 28e403b | 2017-10-25 16:16:38 -0500 | [diff] [blame] | 4 | # simplest of programs where all program parameters are positional, there is no |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 5 | # help text, etc. |
| 6 | |
| 7 | # Description of argument(s): |
| 8 | # parm1 Bla, bla, bla (e.g. "example data"). |
| 9 | |
| 10 | |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 11 | function get_parms { |
| 12 | |
| 13 | # Get program parms. |
| 14 | |
| 15 | parm1="${1}" ; shift |
| 16 | |
| 17 | return 0 |
| 18 | |
| 19 | } |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 20 | |
| 21 | |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 22 | function validate_parms { |
| 23 | |
| 24 | # Validate program parameters. |
| 25 | |
| 26 | # Your validation code here. |
| 27 | |
| 28 | if [ -z "${parm1}" ] ; then |
| 29 | echo "**ERROR** You must provide..." >&2 |
| 30 | return 1 |
| 31 | fi |
| 32 | |
| 33 | return 0 |
| 34 | |
| 35 | } |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 36 | |
| 37 | |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 38 | function mainf { |
| 39 | |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 40 | get_parms "$@" || return 1 |
| 41 | |
| 42 | validate_parms || return 1 |
| 43 | |
| 44 | # Your code here... |
| 45 | |
| 46 | return 0 |
| 47 | |
| 48 | } |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 49 | |
| 50 | |
Michael Walsh | 7d68d00 | 2017-05-05 16:36:54 -0500 | [diff] [blame] | 51 | # Main |
| 52 | |
| 53 | mainf "${@}" |
| 54 | rc="${?}" |
| 55 | exit "${rc}" |