QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1833|回复: 0

请问:case语句是否能够匹配多个选项吗?

[复制链接]
发表于 2009-1-11 12:20:19 | 显示全部楼层 |阅读模式
我编写了一段代码,主要实现从输入的命令行中提取出相关参数的功能,使用了case进行判断,源代码如下 xshift.sh:

#!/bin/sh
while [ $# -ne 0 ]
do
case "$1" in
-[m]?*) # separate flags from value
flag=`expr "$1" : '\(..\)'` #put the first two characters to the flag
arg=`expr "$1" : '..\(.*\)'` #put the other characters to the variable arg
echo $1
echo $flag
echo $arg
shift
set shiftdummy "$flag" "$arg" "$@"
echo "i am in the -[m]?*)"
;;
-m) shift
echo $1
echo "i am in the -m)"
MFLAGS="${MFLAGS}$1"
;;
-*)
;;
*)
;;
esac
shift
done

当我输入指令 ./xshift.sh -mb abc 后,输出的结果如下显示:
-mb
-m
b
i am in the -[m]?*)
b
i am in the -m)


问题出现在:我在case中进行了判断,想实现跳转到其中一个分支中去。可结果却发现,两个分支都进入了。请问这个应该怎么解释?是不是我的代码哪里有问题?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-26 16:10 , Processed in 0.073441 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表