Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1674287
  • 博文数量: 782
  • 博客积分: 2455
  • 博客等级: 大尉
  • 技术积分: 4140
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-06 21:37
个人简介

Linux ,c/c++, web,前端,php,js

文章分类

全部博文(782)

文章存档

2015年(8)

2014年(28)

2013年(110)

2012年(307)

2011年(329)

分类:

2011-09-30 13:19:15

1.opstring  定义命令行中有效的选项字母和对应的参数值。

2.列出定义用到的选项字母,冒号的作用: 在每一个需要参数的选项字母后面放置一个冒号
[root@acer today_bash]# getopt   ab:cd   -a  -b  shell  -c -d   option  parameter    //回车
 -a -b shell -c -d -- option parameter   //其中--的含义:选项列表的结束。发现--后脚本把其后的
命令行参数当作参数处理而不是选项处理。

3. #vim  test1
#!/bin/bash
#test   the  option   between  the  colon

while   getopts  :ab:cdef:  opt
do
  case  "$opt"   in
  a)   echo  "found  the -a option " ;;
  b)   echo  "found  the -b option ,with  the value :$OPTARG " ;;
  c)   echo  "found  the -c option " ;;
  d)   echo  "found  the -d option " ;;
  e)   echo  "found  the -e option " ;;
  f)   echo  "found  the -f option ,with value : $OPTARG" ;;
  *)   echo  "unknown  option : $opt"
  esac
done


[root@acer today_bash]# ./test1   -ab shell   -c -d -e  -k -f  xixi  hehe
found  the -a option
found  the -b option ,with  the value :shell
found  the -c option
found  the -d option
found  the -e option
unknown  option : ?     //由于-k  没有定义  所以调用的时候会出现?
found  the -f option ,with value : xixi       //$OPTARG变量可以重复使用

整明白了。


阅读(387) | 评论(0) | 转发(0) |
0

上一篇:linux下find命令实例

下一篇:shell收集

给主人留下些什么吧!~~