zoukankan      html  css  js  c++  java
  • Bash: parsing arguments with ‘getopts’ | rsalveti's random thoughts

    Bash: parsing arguments with ‘getopts’ | rsalveti's random thoughts:

    #!/bin/bash
    # Argument = -t test -r server -p password -v

    usage()
    {
    cat << EOF
    usage: $0 options

    This script run the test1 or test2 over a machine.

    OPTIONS:
       -h      Show this message
       -t      Test type, can be ‘test1′ or ‘test2′
       -r      Server address
       -p      Server root password
       -v      Verbose
    EOF
    }

    TEST=
    SERVER=
    PASSWD=
    VERBOSE=
    while getopts “ht:r:p:v” OPTION
    do
         case $OPTION in
             h)
                 usage
                 exit 1
                 ;;
             t)
                 TEST=$OPTARG
                 ;;
             r)
                 SERVER=$OPTARG
                 ;;
             p)
                 PASSWD=$OPTARG
                 ;;
             v)
                 VERBOSE=1
                 ;;
             ?)
                 usage
                 exit
                 ;;
         esac
    done

    if [[ -z $TEST ]] || [[ -z $SERVER ]] || [[ -z $PASSWD ]]
    then
         usage
         exit 1
    fi

    (Via.)

  • 相关阅读:
    Windows 7 SP1无人值守自动应答文件制作
    Ubuntu GNOME单击任务栏图标最小化设置
    NOIP2017题解
    NOIP2017游记
    大模拟1.0
    奇袭
    礼物
    找硬币
    Fiolki
    SQLserver Delete from where 与Oracle delete from where 的差异
  • 原文地址:https://www.cnblogs.com/devops/p/3152500.html
Copyright © 2011-2022 走看看