[dev] Re: [dev] Re: [dev] [dev] Usage, -h, --help, help, synopsis, …

From: yy <yiyu.jgl_AT_gmail.com>
Date: Sat, 21 Aug 2010 13:22:21 +0200

2010/8/19 Suraj Kurapati <sunaku_AT_gmail.com>:
> On Tue, Aug 17, 2010 at 7:54 PM, Suraj Kurapati <sunaku_AT_gmail.com> wrote:
>> On Tue, Aug 17, 2010 at 8:40 AM, Alexander Teinum <ateinum_AT_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

I find this solution really convoluted. Why not using echo? You can
use an USAGE variable, or even a here-document and cat<< if you feel
like it. And btw, it would probably be a good idea to redirect the
help message to stderr.

-- 
- yiyus || JGL . 4l77.com
Received on Sat Aug 21 2010 - 13:22:21 CEST

This archive was generated by hypermail 2.2.0 : Sat Aug 21 2010 - 13:24:02 CEST