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

2013年(2)

2012年(18)

2011年(116)

分类: Python/Ruby

2011-09-26 17:14:17

1.   shift 命令   默认将每一个参数左移一个位置,$3挪到$2   $2挪到$1   $1值丢弃  $0保持程序名称值不变
2.   shift  在case  里面可以实现对应参数从参数变量中丢弃
      #vim    test0
        #!/bin/bash
        num=1
        while  [  -n  "$1" ]
           do
               echo  "parameter  # $num = $1"
               num=$[ $num 1]
               shift                 //改成  shift  2    则死循环了$1 的值会出现问题
           done
 
3.  移位时 shift 命令难道就只能移一位吗?

4.getopt 命令处理选项---针对多个参数时    

#!/bin/bash
#  extracting  command  line options  and values  with  grtopt

set  --  'getopt -q ab:c "$@"'  //出错!!!!
while [ -n "$1" ]
do
  case  "$1"  in
  -a)   echo  " found  the  -a  option ";;
  -b)   param="$2"
        echo  "found the -b option ,with parameter value $param"
        shift  ;;
  -c)   echo "found  the -c  option" ;;
  --)  shift
       break ;;
  *)    echo  "$1  is not  an  option"  ;;
 esac
   shift
done

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

[root@acer today_bash]# sh   test8    -cd
getopt -q ab:c "$@"  is not  an  option
[root@acer today_bash]# ./test8    -cd
getopt -q ab:c "$@"  is not  an  option      //等待解决------Richard  Blum [A]  195页 人民邮电

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