-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbash-template
More file actions
executable file
·72 lines (61 loc) · 1.5 KB
/
bash-template
File metadata and controls
executable file
·72 lines (61 loc) · 1.5 KB
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
#!/bin/bash
# More safety, by turning some bugs into errors.
set -euCo pipefail
IFS=$'\n\t'
scriptDirectory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# temp directory
tempDirectory=$(mktemp -d -t tmp.XXXXXXXXXX)
function cleanup {
rm -rf "$tempDirectory"
}
trap cleanup EXIT
# arguments parsing
OPTIONS=hpt
LONGOPTS=help,parameters,temporary
parameters="false"
temporary="false"
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
exit 2
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
echo "<command description>"
echo "$0 [<optional arguments>] <required arguments>"
echo ""
echo "-p|--parameters - add parameter parsing logic"
exit 1
;;
-p|--parameters)
parameters="true"
shift
;;
-t|--temporary)
temporary="true"
shift
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
# handle non-option arguments
if [[ $# -ne 0 ]]; then
echo ""
echo "Use -h to see more info"
exit 4
fi
cat "$scriptDirectory/bash-template-essential.sh"
if [[ "$temporary" == "true" ]]; then
cat "$scriptDirectory/bash-template-temporary.sh"
fi
if [[ "$parameters" == "true" ]]; then
cat "$scriptDirectory/bash-template-parameters.sh"
fi