How to create a bash script that takes arguments?

后端 未结 5 1537
一整个雨季
一整个雨季 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:10

    And I heard a completely opposite thing, that you shouldn't use getopt, but the getopts builtin.

    Cross-platform getopt for a shell script

    Never use getopt(1). getopt cannot handle empty arguments strings, or arguments with embedded whitespace. Please forget that it ever existed.

    The POSIX shell (and others) offer getopts which is safe to use instead.

提交回复
热议问题