1

I know boost::program_options from c++ which enables me to write user- friendly command-line options in almost no time. With "user- friendly" I mean, short and long options and a descriptive help command which would look similar to this:

Copy standard input to each FILE, and also to standard output.

  -a, --append              append to the given FILEs, do not overwrite
  -i, --ignore-interrupts   ignore interrupt signals
      --help     display this help and exit
      --version  output version information and exit

For myself I had to find out that this is really awkward in bash with the built-in getopts only supporting short options. Is this correct or am I wrong?

How would you implement user friendly command line options? If you know any links, best practices or in depths tutorials I would be really much appreciated.

Mythli
  • 5,995
  • 2
  • 24
  • 31
  • See: http://stackoverflow.com/questions/402377/using-getopts-in-bash-shell-script-to-get-long-and-short-command-line-options – pb2q Aug 15 '12 at 23:14

2 Answers2

1

GNU getopt supports long options and can be used from any Bourne-like or csh-like shell. ksh93's builtin getopts supports long options as well. zsh has a zparseopts.

There's a POSIX shell implementation of getopts (as a shell function) that supports long options at http://stchaz.free.fr/getopts_long.sh

Stephane Chazelas
  • 5,859
  • 2
  • 34
  • 31
0

Thank you for pointing me to the correct sources of information.

I decided to do it this way https://github.com/Mythli/tech/blob/master/bash/getopt.sh The code is pretty straightforward so no explanation should be needed.

Mythli
  • 5,995
  • 2
  • 24
  • 31