Self documenting bash script options

This Linux HOWTO describes a process to display a help window for a bash script that has several command line options.

Most bash scripts can be called with a varying number of options (using the getopts syntax) and it is sometimes hard keeping up with what each option does, particularly if there are many.

Inside the script these options are managed in the getops list, so a print-out of the current option list is useful. However, the options may change in time and short of updating a help message file each time, or opening the script and viewing the relevant area, it is useful to provide a synchronised way of displaying the options in a readable format.

A typical getopts sequence might look like the following:

In this case the area of interest is the getops sequence and to demarcate this place ###START (3 '#') at the start and ####END at the end of the sequence (as these are comments they can be inserted anywhere).

The following function within the script then gathers all lines between ###START and ####END, tidies the content up a bit (this is optional) and shows the result in a zenity window.