-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTemplate.sh
executable file
·104 lines (92 loc) · 2.76 KB
/
Template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#! /usr/bin/env sh
# Copyright (C) 2021 Nathan Paul Simons ([email protected])
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Debugging/error checking options; see the bash manual page for details.
# Set the prompt for trace output.
# This sets the execution trace prompt string (PS4) to the program name
# ($0), "line" and line number ($LINENO) within the program.
if test ${LINENO:-set} != set; then
PS4='$0 line $LINENO: '
else
PS4='$0: '
fi
# Print shell input lines as they are read.
set -o verbose
# Print expanded commands.
set -o xtrace
# Exit immediately if a simple command fails.
set -o errexit
# Don't overwrite existing files.
# NOTE: this only applies to shell-script things like redirection; the
# executables called below will still be able to overwrite files.
set -o noclobber
# Treat unset variables as an error.
set -o nounset
# Fail if any command in a pipeline fails; non-POSIX shell extension.
if test "${BASH_VERSION:-set}" != set; then
set -o pipefail
fi
show_help()
{
echo "$0: A template shell script for quick prototyping and testing."
echo " -h, -?, --help Print this help message."
echo " -v, --verbose Be verbose."
}
if test $# -eq 0; then
show_help
exit
fi
optspec="hf:v-:"
while getopts "${optspec}" optchar; do
case "${optchar}" in
-)
case "${OPTARG}" in
help)
show_help
exit 0
;;
verbose)
verbose=1
;;
*)
echo "Unrecognized option --${OPTARG}."
show_help
exit 1
;;
esac;;
h|\?)
show_help
exit 0
;;
v)
verbose=1
;;
f)
output_file=$OPTARG
;;
?)
echo "Unrecognized option -${optchar}."
show_help
exit 1
;;
esac
done
# Local Variables:
# mode: Shell-Script
# sh-indentation: 4
# indent-tabs-mode: nil
# sh-basic-offset: 4
# End:
# vi: fileformat=unix filetype=sh shiftwidth=4 tabstop=4 expandtab