[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function with description
From: |
Greg Wooledge |
Subject: |
Re: function with description |
Date: |
Mon, 28 Jun 2021 18:40:03 -0400 |
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.