#!/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)