Using getopts to process long and short command line options

后端 未结 30 1601
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 22:52

I wish to have long and short forms of command line options invoked using my shell script.

I know that getopts can be used, but like in Perl, I have not

30条回答
  •  心在旅途
    2020-11-21 23:17

    EasyOptions handles short and long options:

    ## Options:
    ##   --verbose, -v   Verbose mode
    ##   --logfile=NAME  Log filename
    
    source easyoptions || exit
    
    if test -n "${verbose}"; then
        echo "log file: ${logfile}"
        echo "arguments: ${arguments[@]}"
    fi
    

提交回复
热议问题