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

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

 

相关文章:

  • 2021-11-11
  • 2021-09-08
  • 2022-12-23
  • 2022-02-11
  • 2022-02-12
  • 2021-04-17
  • 2021-12-27
  • 2022-02-25
猜你喜欢
  • 2022-12-23
  • 2021-12-19
  • 2021-06-07
  • 2021-12-31
  • 2021-07-12
  • 2021-07-10
  • 2021-09-09
相关资源
相似解决方案