码迷,mamicode.com
首页 > 系统相关 > 详细

shell参数处理模板

时间:2017-08-31 17:54:31      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:shel   exit   表示   span   bsp   div   处理   参数   cas   

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

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

 

shell参数处理模板

标签:shel   exit   表示   span   bsp   div   处理   参数   cas   

原文地址:http://www.cnblogs.com/tibit/p/7459378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!