On Tue, Aug 17, 2010 at 7:54 PM, Suraj Kurapati <sun...@gmail.com> wrote:
> On Tue, Aug 17, 2010 at 8:40 AM, Alexander Teinum <atei...@gmail.com> wrote:
>> What is the most concise way of outputting a usage and help text?
>
> For my programs, the --help option simply displays their manpage. :-)

Alternatively, in simple shell scripts (for which writing a manpage
would be overkill), I simply print the script file's comment header
using sed(1):

#!/bin/sh
# your program description & usage documentation here
# nicely formatted and beautified to fit 80 columns
# NOTE: the blank line below is the end of the file comment header

# check command-line usage
if test "$#" -lt 3; then
  sed -n '2,/^$/s/^# \?//p' "$0" # show this file's comment header
  exit 1
fi

Reply via email to