-
Notifications
You must be signed in to change notification settings - Fork 7
/
sh
43 lines (33 loc) · 845 Bytes
/
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
#!/bin/bash
## DESCRIPTION:
\## AUTHOR: $USER_FULLNAME
declare -r SCRIPT_NAME=\$(basename "\$BASH_SOURCE" .sh)
## exit the shell(default status code: 1) after printing the message to stderr
bail() {
echo -ne "\$1" >&2
exit \$\{2-1}
}
## help message
declare -r HELP_MSG="Usage: $SCRIPT_NAME [OPTION]... [ARG]...
-h display this help and exit
"
## print the usage and exit the shell(default status code: 2)
usage() {
declare status=2
if [[ "\$1" =~ ^[0-9]+$ ]]; then
status=\$1
shift
fi
bail "\$\{1}\$HELP_MSG" \$status
}
while getopts ":h" opt; do
case \$opt in
h)
usage 0;;
\?)
usage "Invalid option: -\$OPTARG \\n";;
esac
done
shift \$((\$OPTIND - 1))
[[ "$#" -lt 1 ]] && usage "Too few arguments\\n"
#==========MAIN CODE BELOW==========