#!/bin/bash
while getopts "fh:" opt
do
case "$opt" in
f)
echo "option $opt is specified"
;;
h)
echo "option $opt has value $OPTARG"
;;
\?)
echo "unknow option $OPTARG"
;;
:)
echo "no parameter value for option $OPTARG"
;;
*)
echo ""unknown error"
;;
esac
done
shift $(($OPTIND -1))
for opt in "$@"
do
if [ ! -f $2 ]
then
echo "cat not find file $opt"
else
echo "file the file $opt"
fi
done
getopts 获取连字符后面的单字符变量,如果匹配成功在设置为匹配值,否则设置为?
shift向左偏移一个位置