码迷,mamicode.com
首页 > 系统相关 > 详细

shell getopts and getopt用法

时间:2015-05-02 16:29:53      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

 1 #!/bin/bash
 2 TEMP=`getopt -o hm: --long aai:,mai: -n getopts.sh  -- "$@"`
 3 eval set --  "$TEMP"
 4 while true
 5 do
 6 case "$1" in
 7     -h|--aai)
 8     echo $2
 9     shift 2;;
10     -m|--mai)
11     echo $2
12     shift 2;;
13     --)
14     shift
15     break;;
16     *)
17     exit 1;;
18 esac
19 #case "$2" in
20 #        -m|--mai)
21 #        echo mai
22 #        exit;;
23 #esac
24 
25 done
26 [root@www python_back]# cat getopts.sh 
27     #!/bin/bash 
28     echo "OPTIND starts at $OPTIND" 
29     while getopts ":pq:" optname 
30     do 
31         case "$optname" in 
32         "p") 
33             echo "Option $optname is specified" 
34             ;; 
35         "q") 
36             echo "Option $optname has value $OPTARG" 
37             ;; 
38         "?") 
39             echo "Unknown option $OPTARG" 
40             ;; 
41         ":") 
42             echo "No argument value for option $OPTARG" 
43             ;; 
44         *) 
45             # Should not occur 
46             echo "Unknown error while processing options" 
47             ;; 
48         esac 
49         echo "OPTIND is now $OPTIND" 
50     done 

 

shell getopts and getopt用法

标签:

原文地址:http://www.cnblogs.com/zenghui940/p/4472104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!