Ask HN: How do you implement option flags in your shell scripts?
What common patterns, conventions, or idioms do you use to implement options in your shell scripts?
Examples of options I want to implement: - [-h | --help] Prints a help message. - [-t | --target] Points to a directory containing our automated tests. - [-e | --env] Takes a string URI for the automated tests to run against (e.g. http://localhost:1234 or https://tst.mycloudenv.hn). - [-q | --quiet] Suppresses output.
Capabilities: - Long or short options. - Options can appear in any order. - Options are properly interpreted anywhere in the command, besides the last position. - Short options can be concatenated.
Essentially, I want these to be as professional and POSIX compliant as possible [0].
[0] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
4 comments
[ 4.4 ms ] story [ 24.8 ms ] thread[1] - https://stackoverflow.com/questions/7069682/how-to-get-argum...