The history of command line option syntax in Unix and its descendants is long and twisted. I haven't learned all there is to know about this history, but I have inferred much (sometimes incorrectly) from my own experience. Two good examples of this long and twisted history are the manpages for
ls and
ps.
In any case, check the man page and
GNU info manual for details.
Quote:
Originally Posted by Hevithan
What i am wondering is, Do most '-' commands have a counter part that you can use with '--', and vice versa?
|
It varies from command to command. Check the man page and GNU info manual for details.
Quote:
Such as -h and --help being used the same way?
|
Some commands support one or the other, but some support both or neither. In general, I have found it to be safe to assume all programs will provide some helpful information when given '--help', but there are exceptions.
The
GNU Coreutils Manual says:
Quote:
Most programs that accept long options recognize unambiguous abbreviations of those options. For example, ‘rmdir --ignore-fail-on-non-empty’ can be invoked as ‘rmdir --ignore-fail’ or even ‘rmdir --i’. Ambiguous options, such as ‘ls --h’, are identified as such.
Some of these programs recognize the --help and --version options only when one of them is the sole command line argument. For these programs, abbreviations of the long options are not always recognized.
‘--help’
Print a usage message listing all available options, then exit successfully.
|
Check the program's man page and GNU info manual for details.
Quote:
and if so are there benefits other then convenience (for times when you enter multiple options)?
|
In general you should choose an options syntax which you understand well and is unambiguous. As you become more familiar with a command you will develop a better understanding of its option syntax. Check the man page and GNU info manual for details.
GNU programs seem to use '--long-option' more for options which weren't available on traditional Unix versions of the command. GNU programs also provide many '--long-option' formats for many options which already have well known '-x' (single hyphen followed by single letter) formats.
If I were to generalize command line option syntax I'd probably say there are two categories:
binary options (on or off), and
settings for internal variables.
Binary (on|off) Options
A binary option has only two possible states:
on or
off. A good example which is supported by most commands is
verbosity. According to Unix tradition, most programs produce little or no output on the terminal unless something goes wrong. For example,
rm is completely silent if the file was removed successfully.
Code:
foo$ rm infile
foo$
If you want
rm to explicitly state what is being done, you can pass it the
-v option.
Quote:
Originally Posted by man rm
-v, --verbose
explain what is being done
|
Code:
foo$ rm -v t
removed `t'
foo$
The
verbose option is what I call a
binary option, because it can only be either
on or
off. Notice that there are both short form and long form options for
verbosity in many programs.
Settings For Internal Variables
Most programs use many variables internally which determine what actions are taken and how they are performed. Programmers reveal some of these variables to users through command line options. For example, consider the
options for GNU date:
Quote:
Originally Posted by info coreutils 'date invocation'
‘-d datestr’
‘--date=datestr’
Display the date and time specified in datestr instead of the current date and time. datestr can be in almost any common format. It can contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc. For example, --date="2004-02-27 14:19:13.489392193 +0530" specifies the instant of time that is 489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30 minutes east of UTC.
Note: input currently must be in locale independent format. E.g., the LC_TIME=C below is needed to print back the correct date in many locales:
date -d "$(LC_TIME=C date)"
|
Code:
foo$ date
Fri May 27 17:55:15 EDT 2011
foo$ date -d "tomorrow"
Sat May 28 17:55:22 EDT 2011
foo$ date --date="next monday"
Mon May 30 00:00:00 EDT 2011
foo$
The
date string is an internal variable which the
date command uses to determine which date is desired. If none is specified, then the
date command automatically initializes
date string to
now, just as if you had typed
date -d "now". Alternate dates may be specified with either
--date=date string (long format) or
-d date string (short format).
For more information about command line options and how they are parsed you might read the manpages for
man 1 getopt and
man 3 getopt.
HTH