Chinaunix首页 | 论坛 | 博客
  • 博客访问: 419322
  • 博文数量: 136
  • 博客积分: 5351
  • 博客等级: 少校
  • 技术积分: 1446
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-29 15:46
文章存档

2013年(2)

2012年(18)

2011年(116)

分类: Python/Ruby

2011-09-27 10:50:06

1.getopts  是 getopt  的加强版   每调用一次getopts 只处理在命令中检测到的一个参数。处理完以大于0的
   退出状态退出。是不是环境变量OPTIND的值呢?
  A:OPTIND值表示getopts停止处理时在参数列表中的位置.

2.getopts另一个环境变量OPTARG包含需要参数值的选项要使用的值.


3.   vim    test0
#!/bin/bash

echo   " num1 the  value of optind : $OPTIND"
while   getopts     :a:c:b:d    opt      //在选项字符串中列出脚本中用到的每个命令行选项字母
do                                                              每个需要的参数值的选项字母后面要放置一个冒号
  echo   "num2   the  optind  value  : $OPTIND"
   case "$opt"  in
   a)   echo  "found  the -a  option " ;;
   b)   echo  "found  the -b  option , with the option  $OPTARG" ;;
   c)   echo  "found  the -c  option ,with  an option  $OPTARG" ;;
   d)   echo  "found  the -d  option " ;;
   *)   echo  "unknown  option : $opt" ;;
   esac
done
echo "the optind  value is : $OPTIND"
shift  $[ $OPTIND - 1 ]

num=1
for  param   in  "$@"
do
   echo  "parameter  $num:   $param"
   count=$[ $num + 1 ]
done

可以测试分析一下OPTIND的生成。  


阅读(592) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~