4 ms·
You can use getopt in POSIX shell too - https://github.com/yoshuawuyts/knowledge/blob/master/unix/shell.md#command-line-switches https://github.com/yoshuawuyts/
by yoshuaw 11y ago
You can use getopt in POSIX shell too - https://github.com/yoshuawuyts/knowledge/blob/master/unix/shell.md#command-line-switches https://github.com/yoshuawuyts/knowledge/blob/master/unix/sh...
- cperciva 11y agoThis still has the "list the options twice" wart though. Of course there's no way to avoid that for shell scripts, since getopt(1) has to explode the options before the rest of your script starts looking at them.
- pdkl95 11y agoTo add to this, here's a full example of conditionally using getopt that still works without it. It also includes an example of the recommended-by-GNU help and version options, which jzwinck mentioned. https://gist.github.com/pdkl95/363d48999e9df027a99c https://gist.github.com/pdkl95/363d48999e9df027a99c