-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathoption.sh
69 lines (65 loc) · 1.6 KB
/
option.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
#!/bin/bash
#将规范化后的命令行参数分配至位置参数($1,$2,...)
temp=`getopt -n $0 -o ut:r:p:: -l help,tlong:,long-t1:,long-t2:: -- "$@"`
[ $? != 0 ] && {
echo 'Try '$0 '--help for more information.'
exit 1
}
set -- $temp
while true;do
case "$1" in
-u)
echo '-u has be used';
shift
;;
-r)
echo '-r has be used with:' $2;
shift 2
;;
-p)
case "$2" in
"")
echo '-p has be used without arg'
shift 2
;;
*)
echo '-p has be used with:' $2
shift 2
;;
esac
;;
-t|--tlong)
echo '-t or --tlong has be used with: ' $2
shift 2
;;
--help)
#help_function_msg
echo 'some information about how to usage'
shift 1
;;
--long-t1)
echo '--long-t1 has be used with: ' $2
shift 2
;;
--long-t2)
case "$2" in
"")
echo '--long-t2 has be used without arg'
;;
*)
echo '--long-t2 has be used with:' $2
shift 2
;;
esac
;;
--)
shift
break
;;
*)
[[ -z "$1" || "$1" == '--' ]] && { shift;break; }
echo "Internal error!"
exit 1
;;
esac
done