help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

function with description


From: lisa-asket
Subject: function with description
Date: Tue, 29 Jun 2021 01:40:43 +0200 (CEST)

>You can add argument (option) processing and have the function print a
>usage message to stderr (or stdout) when invoked incorrectly. One of my
>earlier examples did precisely that.



Is that when you used



if (($# != 3)); then
echo 'usage: print-lines startnum endnum startdir' >&2
return 1
fi



Need  something more elaborate than that.  Something that matches

"help", "-h", "-?" and "--help".



Thanks




From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: function with description
Date: 29/06/2021 00:40:03 Europe/Paris

On Tue, Jun 29, 2021 at 12:29:01AM +0200, lisa-asket@perso.be wrote:
> Perhaps I can call the function this way `headrc h`

You can add argument (option) processing and have the function print a
usage message to stderr (or stdout) when invoked incorrectly. One of my
earlier examples did precisely that.

In my example, I printed the message if the function was called with
anything other than 3 arguments. Calling it with the single argument
"h" would definitely trigger it.

More generally, if you write a command (function, script, whatever) that
accepts a variable number of arguments, and would like to reserve one
special option for "tell me how to use you", the traditional choices
are "help", "-h", "-?" and "--help". ("help" without a leading hyphen
only makes sense for commands that have a mandatory subcommand argument.)

I've never seen anyone rsserve "h" for this purpose, but it's your
command, and you can write it however you wish.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]