Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 12
    getopt, except for the GNU version (which has a different calling convention), is fundamentally broken. Do not use it. Please use **getopts instead bash-hackers.org/wiki/doku.php/howto/getopts_tutorial Commented Aug 20, 2009 at 23:21
  • 10
    @hendry - from your own link: "Note that getopts is not able to parse GNU-style long options (--myoption) or XF86-style long options (-myoption)!" Commented Jul 18, 2011 at 19:32
  • 1
    Jonathan -- you should rewrite the example to use eval set with quotes (see my answer below) so that it also works correctly with GNU getopt (the default on Linux) and handles spaces correctly. Commented Jul 22, 2012 at 0:25
  • 1
    The link from @hendry’s comment (the first comment to this answer) has moved to wiki.bash-hackers.org/howto/getopts_tutorial Commented Oct 13, 2021 at 16:12
  • 1
    wiki.bash-hackers.org/howto/getopts_tutorial no more exists; use the archived version: web.archive.org/web/20200507131743/https:/wiki.bash-hackers.org/… Commented Jun 2, 2024 at 22:04