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页 人民邮电
阅读(488) | 评论(0) | 转发(0) |