-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.sh
52 lines (47 loc) · 962 Bytes
/
options.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
#!/usr/bin/env -S bash
[ -p /dev/stdin ] &&set -- $@ $(cat -)
_ver() {
echo "Version:β0.1"
}
_usage() {
cat << EOF
$(figlet $0)
$(_ver)
-v --version Show version
-h --help Get help
EOF
}
declare -i argc=0
declare -a argv=()
while (( $# > 0 )); do
case $1 in
-[A-Za-z0-9]*)
echo a
if [[ "$1" =~ "v" ]];then
_ver
fi
if [[ "$1" =~ "h" || "$1" =~ "*" ]];then
_usage
fi
shift
;;
--[A-Za-z0-9]*)
if [[ "$1" = "--version" ]];then
_ver
fi
if [[ "$1" = "--help" ]];then
_usage
fi
if [[ "$1" = "--*" ]];then
_usage
fi
shift
;;
*)
_usage
((++argc))
argv=("${argv[@]}" "$1")
shift
;;
esac
done