How to create a bash script that takes arguments?

后端 未结 5 1595
一整个雨季
一整个雨季 2021-01-31 10:33

I already know about getopts, and this is fine, but it is annoying that you have to have a flag even for mandatory arguments.

Ideally, I\'d like to be able to have a scr

5条回答
  •  误落风尘
    2021-01-31 11:24

    If you are using getops, just shift by $OPTIND-1 after your case statement. Then what is left in $* will be everything else, which is probably what you want.

    shift $(( ${OPTIND} - 1 )); echo "${*}"
    

提交回复
热议问题