I'm looking for way to process shell script arguments that is cleaner and more "self documenting" than getopt/getopts.
It would need to provide…
- Full support of long options with or without a value after '=' or ' '(space).
- Proper handling of hyphenated option names (i.e. –ignore-case)
- Proper handling of quoted option values (i.e. –text "A text string")
I would like to eliminate the overhead of the big loop with embedded case statement that getopt/getopts requires and reduce option processing to something like…
option=argumentparse "$@"
[[ option == "" ]] && helpShow
[[ option =~ -h|--help ]] && helpShow
[[ option =~ -v|--version ]] && versionShow
[[ option =~ -G|--GUI ]] && GUI=$TRUE
[[ option =~ --title ]] && TITLE=${option["--title"]}
Here, an argumentparse() function resolves the various syntax possibilities into a consistent format, perhaps an associative array.
There must be something coded out there somewhere. Any ideas?
(updated and retitled)
Best Answer
Since this question has been viewed so much (for me at least) but no answers were submitted, passing on the solution adopted...
NOTE
Some functions, like the multi-interface output functions
ifHelpShow()
anduiShow()
are used but not included here as their calls contain relevant information but their implementations do not.