Quantcast
Channel: getopt, getopts or manual parsing - what to use when I want to support both short and long options? - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 6

getopt, getopts or manual parsing - what to use when I want to support both short and long options?

$
0
0

Currently I'm writing a Bash script which has the following requirements:

  • it should run on a wide variety of Unix/Linux platforms
  • it should support both short and (GNU) long options

I know that getopts would be the preferred way in terms of portability but AFAIK it doesn't support long options.

getopt supports long options but the BashGuide recommends strongly against it:

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

So, there still is the option of manual parsing. This is error-prone, produces quite some boilerplate code, and I need to handle errors by myself (I guess getopt(s) do error-handling by themselves).

So, what would be the preferred choice in this case?


Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images