unixscripts:3-decentbash
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
decentbash [2015/12/31 03:04] – [Use **getopt**(1)] admin | unixscripts:3-decentbash [2020/10/17 03:04] (current) – admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Decent Bash===== | + | =====Unixscripts: |
Here's my five penn' | Here's my five penn' | ||
Line 12: | Line 12: | ||
* plain old simple works - why write bug-prone new code when **getopt**(1) just works? | * plain old simple works - why write bug-prone new code when **getopt**(1) just works? | ||
- | ====Use | + | ====Use argp.sh(1)==== |
- | Even better, use my **getopt**(1) wrapper [[argp.sh]] which is kinda sorta like GNU's **argp**(3) in glibc. It gives you a single place to define options which is then used to: | + | Even better, use my **getopt**(1) wrapper [[unixscripts: |
* create the **getopt**(1) command line, | * create the **getopt**(1) command line, | ||
* process the options setting appropriate environment parameters | * process the options setting appropriate environment parameters | ||
* print help & man pages without any extra code | * print help & man pages without any extra code | ||
* honours GNU's [[http:// | * honours GNU's [[http:// | ||
- | * is pretty similar to GNU's **argp**(3) **getopt**(3) wrapper in glibc | + | * is pretty similar to GNU's **argp**(3) |
* further reduces the chance of bugs arising - particularly as the script is maintained | * further reduces the chance of bugs arising - particularly as the script is maintained | ||
* increase the chance that help and man pages are actually written | * increase the chance that help and man pages are actually written | ||
- | ====Long options==== | + | ====Support |
Always provide long options as well as single letter options - they' | Always provide long options as well as single letter options - they' | ||
====Provide help==== | ====Provide help==== | ||
- | respond to the **-h, --help** option with a usage message to **!!!STDOUT!!!** and exit 0 | + | respond to the **-h, --help** option with a usage message to **!!!STDOUT!!!** and exit 0. This help should be available no matter what the machine' |
+ | |||
+ | If there are specific dependencies, | ||
====Provide version info==== | ====Provide version info==== | ||
- | provide a way to get the program' | + | provide a way to get the program' |
Note that **-h** and **-V** processing should happen before any other substantial processing or checking is done - make sure **-h** can always be done no matter what | Note that **-h** and **-V** processing should happen before any other substantial processing or checking is done - make sure **-h** can always be done no matter what | ||
- | ====Error messages==== | + | ====Be disciplined with error messages==== |
Error messages should go to **!!!STDERR!!!** - do **not** print the usage as it just fills the screen and hides the meat of the error. At the most, refer the user to the usage page with '' | Error messages should go to **!!!STDERR!!!** - do **not** print the usage as it just fills the screen and hides the meat of the error. At the most, refer the user to the usage page with '' | ||
- | ====Error exit==== | + | ====Be disciplined with error exit codes==== |
non-zero exit on any error | non-zero exit on any error | ||
Line 42: | Line 44: | ||
execute as silently as possible so the user doesn' | execute as silently as possible so the user doesn' | ||
- | The exception, of course, is if a verbosity command is given, generally with **-v/--verbose** - and the output goes to stdout, thank you very much (so we can distinguish bash's own -x output which goes to stderr) | + | The exception, of course, is if a verbosity command is given, generally with **-v, --verbose** - and the output goes to stdout, thank you very much (so we can distinguish bash's own -x output which goes to stderr) |
====man(1) page==== | ====man(1) page==== | ||
include a man page if non-trivial | include a man page if non-trivial | ||
- | ====crunchbang==== | + | ====Use a crunchbang==== |
always include the // | always include the // | ||
unixscripts/3-decentbash.1451556241.txt.gz · Last modified: 2015/12/31 03:04 by admin