I'm currently developing a shell script, called up, which shows a usage string on the commandline when called with --help. The output looks like this:

$ up --help
usage: up [-n levels][--help][--versions][basename]...

This looks okay but I'm wondering if I actually need to show the --help and --version options because they are a widely accepted standard and only seem to add noise to the usage string.


This is entirely up to you but most programs do someting like this

program --help

Usage: program [<options>][<arguments> ...]

--help         show this message, then exit
--something    after some spaces for alignment, an explenation follows.

You should check out getopt which most programs (this is also available in programming languages) and scripts use. This way people using your script will not get confused.

Finally, you should add all your options even if they seem trivial to you to be complete. So, I would add both --help and --version in the Options section of the usage.

  • 1
    +1 for usage consistency across different tools (there seem to be several getopt(s), btw) – sr_ Jan 26 '13 at 11:01
  • 2
    +1 most of the gnu tools conform to @silverrocker's style too. It's always nice when scripts/commands have a similar look and feel when looking at their usage. Just look at how ls --help and du --help present their usage info and follow their lead. – slm Jan 26 '13 at 11:03
  • 2
    The getopt command is not in the standard Unix toolchest. There exist several differing implementations with different interfaces. getopts is standard, but the standard doesn't cover GNU-style long options. There's a getopts_long.sh there for a POSIX implementation as a shell function. – Stéphane Chazelas Jan 26 '13 at 12:12
  • +1 This looks like an awesome solution. Is this somewhere documented? I often have a hard time finding resources which tell you how something like this should be implemented (so that it will be consistent across different tools). – helpermethod Jan 27 '13 at 11:03
  • 1
    I've been in the same position not knowing how I should do things properly. I have read the Gnu Coding Standard (gnu.org/prep/standards/standards.html) which answers some of the questions you might have about standardization and consistency. The relevant section for arguments is "Standards for Command Line Interfaces". – Silverrocker Jan 28 '13 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.