1

Some command and programs use -h to show help, some use --help and a few recognize both. It make me crazy. Is there any rule to choose the correct one?

5
  • I think -h is short for --help like -c for -command and etc depending on command or program you want to use. Jan 18, 2015 at 12:30
  • Hmm, tagged cmd.exe. Is this a question for both windows and linux programs in general?
    – Hennes
    Jan 18, 2015 at 12:34
  • @Hennes My main concern is Linux Jan 18, 2015 at 12:54
  • No role exist. You should try any of them. Or better use man command Jan 18, 2015 at 12:59
  • Related: superuser.com/questions/372203
    – Daniel Beck
    Jan 18, 2015 at 14:03

2 Answers 2

2

I'm afraid there is no rule: blame history.

Originally DOS and its predecessors used /?, while Unix used - as an option indicator, since / was a directory separator; since the shell could expand -? into a different string by file name expansion, -h became the norm.

So far, so comparatively straightforward.

In cmd many commands retain the /? convention, but those transcribed from Unix/Linux may use -h, /h or /help.

Meanwhile in Linux some commands became so all-embracing that most of the alphabet was used in options, so the the more verbose -- became used for options, with the single - retained as an alternative for the more common options. And that's where the conflicts started: in commands like ls and du it was felt that -h was better used as a synonym for the lengthy --human-readable, as it was likely to be called on more often than help.

To complicate things further, the local language versions of a few programs have translated the parameters, so that in French the help option becomes -a from aider or assister, for example.

One thing that often works is --: this is nearly always an invalid option, and the program will usually report an error, and then give either the full help or tell you what the help option is.

Ultimately users are subject to the whim of the programmers: both Windows and Linux have utilities written by a huge and disparate number of people, and we are in their hands.

I would like it to be different, but ultimately we have to work with what is available, or spend our lives maintaining our own versions.

0
0

This is because of following reason:

First of all, most linux commands support parameters by using following function :

getopt() and getopt_long().

getopt() was used to support single character with an "-" to distinguish various options

The long option i.e getopt_long() (ex : --help) is a GNU extension that provides more readability and also understanding of the meaning of parameters.

getopt_long() supports both short and long parameter typing and thats why many of the commands may support both.

Another reason one would like to support both parameters is : Keeping backward compatibility.

JFYR : http://en.wikipedia.org/wiki/Getopt

I hope above helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .