您的位置:首页 > 运维架构 > Shell

shell参数处理模板

2017-08-31 17:22 525 查看

存一份模板,以后简单参数处理就用它了

#!/bin/bash
while getopts h:ms option #选项后面的冒号表示该选项需要参数
do
case "$option" in
h)
echo "option:h, value $OPTARG"  #参数存在$optarg中
echo "next arg index:$OPTIND";;
m)
echo "option:m"
echo "next arg index:$OPTIND";;
s)
echo "option:s"
echo "next arg index:$OPTIND";;
\?) #当有不认识的选项的时候arg为?
echo "Usage: args [-h n] [-m] [-s]"
echo "-h means hours"
echo "-m means minutes"
echo "-s means seconds"
exit 1;;
esac
done

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: