Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
howto:getopts_tutorial [2018/03/20 22:58] ffox8 [Description] stop contradicting oneself about professinalism |
howto:getopts_tutorial [2018/03/21 00:07] (current) ffox8 [See also] |
||
---|---|---|---|
Line 4: | Line 4: | ||
===== Description ===== | ===== Description ===== | ||
- | **Note that** ''getopts'' is not able to parse GNU-style long options (''<nowiki>--</nowiki>myoption'') or XF86-style long options (''-myoption'') - so, when you want to parse command line arguments in a real "professional" way, ''getopts'' may or may not work for you. Unlike its older brother ''getopt'' (note the missing //s//!), it's a shell builtin command. The advantages are: | + | **Note that** ''getopts'' is neither able to parse GNU-style long options (''<nowiki>--</nowiki>myoption'') nor XF86-style long options (''-myoption''). So, when you want to parse command line arguments in a professional ;-) way, ''getopts'' may or may not work for you. Unlike its older brother ''getopt'' (note the missing //s//!), it's a shell builtin command. The advantages are: |
* No need to pass the positional parameters through to an external program. | * No need to pass the positional parameters through to an external program. | ||
* Being a builtin, ''getopts'' can set shell variables to use for parsing (impossible for an //external// process!) | * Being a builtin, ''getopts'' can set shell variables to use for parsing (impossible for an //external// process!) | ||
* There's no need to argue with several ''getopt'' implementations which had buggy concepts in the past (whitespace, ...) | * There's no need to argue with several ''getopt'' implementations which had buggy concepts in the past (whitespace, ...) | ||
* ''getopts'' is defined in POSIX(r). | * ''getopts'' is defined in POSIX(r). | ||
+ | |||
+ | ---- | ||
Some other methods to parse positional parameters - using neither **getopt** nor **getopts** - are described in: [[scripting:posparams | How to handle positional parameters]]. | Some other methods to parse positional parameters - using neither **getopt** nor **getopts** - are described in: [[scripting:posparams | How to handle positional parameters]]. | ||
Line 289: | Line 291: | ||
===== See also ===== | ===== See also ===== | ||
- | * [[http://mywiki.wooledge.org/BashFAQ/035|How can I handle command-line arguments (options) to my script easily?]] on Wooledge. | ||
* Internal: [[scripting:posparams]] | * Internal: [[scripting:posparams]] | ||
* Internal: [[syntax:ccmd:case]] | * Internal: [[syntax:ccmd:case]] | ||
* Internal: [[syntax:ccmd:while_loop]] | * Internal: [[syntax:ccmd:while_loop]] | ||
* POSIX [[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html#tag_20_54|getopts(1)]] and [[http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html|getopt(3)]] | * POSIX [[http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html#tag_20_54|getopts(1)]] and [[http://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html|getopt(3)]] | ||
+ | * [[https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash| parse CLI ARGV ]] | ||
+ | * [[http://mywiki.wooledge.org/BashFAQ/035|handle command-line arguments (options) to a script]] | ||
+ |