User Tools

Site Tools


unixscripts:2-argp.sh

This is an old revision of the document!


argp.sh(1) is a bash(1) wrapper around getopt(1) to make life much easier for script developers. It's used in most of my scripts - look at them for examples of use. There's just one essential file to install - the script itself. Put it somewhere on your path, typically in /usr/local/bin:

To use argp.sh(1), a script pipes in a description of its options and gets back the variables as processed by getopt(1) - as a plus it also provides automatic help and man page production.

It buys you:

  • all the goodness of getopt(1)
  • define options in one central place together with descriptions.
  • fewer 'magic' and duplicated values in your code
  • better consistency between the getopt(1) calling parameters, the case statement processing the user's options and the help/man pages
  • less spaghetti in your own code
  • much, much easier to maintain
  • automatic help-page and man-page printing using the same data sources
  • checking of option consistency at runtime
  • range checking of option values at runtime
  • pretty easy to use (just copy and paste from one of my example scripts)
  • portable to OS's without long option support - the help page adapts too

Note that argp.sh(1) deprecates an older script that I wrote called process-getopt(1).

There is also a 'c' version of argp.sh(1) in case you need speed.

To get the latest version of the full source code:

svn checkout svn://svn.code.sf.net/p/argpsh/code/trunk argpsh-code
unixscripts/2-argp.sh.1450182365.txt.gz · Last modified: 2015/12/15 05:26 by admin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki