-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_args.sh
More file actions
63 lines (53 loc) · 1.25 KB
/
Copy pathparse_args.sh
File metadata and controls
63 lines (53 loc) · 1.25 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
#!/bin/bash
#######################################
usage()
{
cat << EOF
Usage: $0 OPTIONS
-h|--help ; help information
--host ; host ip address
--port ; app port
--user ; username
--passwd ; password
EOF
}
parse_args()
{
[ $# -eq 0 ] && { usage; exit 1; }
while [ $# -gt 0 ]; do
case "$1" in
--host)
shift
echo "$1" | grep -iE '^-'
[ $? -ne 0 ] && { HOST_ADDR="$1"; }
;;
--port)
shift
echo "$1" | grep -iE '^-'
[ $? -ne 0 ] && { HOST_PORT="$1"; }
;;
--user)
shift
echo "$1" | grep -iE '^-'
[ $? -ne 0 ] && { USER_NAME="$1"; }
;;
--passwd)
shift
echo "$1" | grep -iE '^-'
[ $? -ne 0 ] && { PASSWD="$1"; }
;;
*)
echo "UNKNOWN ARGUMENTS:$1"
usage
exit 1
;;
esac
shift
done
}
parse_args "$@"
HOST_ADDR=${HOST_ADDR:="127.0.0.1"}
HOST_PORT=${HOST_PORT:="8888"}
USER_NAME=${USER_NAME:="terry"}
PASSWD=${PASSWD:="isme"}
echo "$HOST_ADDR // $HOST_PORT // $USER_NAME // $PASSWD"