A command line consists of a number of 'words' (which may contain spaces,
according to various shell quoting conventions). A word may be an option, an
argument to an option, or a non-option. An option begins with a special
character, usually '-', although '+' is also used sometimes. As special
exceptions, the word containing only a '-' is considered to be a non-option,
since it usually represents standard input or output as a filename, and the
word containing a double-dash '--' is used to mark all following words as
being non-options regardless of their initial character.
Traditionally, all words after the first non-option have been considered to
be non-options automatically, so that options must be specified before
filenames. However, this implementation can extract all the options from the
command line regardless of their position. This can usually be disabled by
setting one of the environment variables 'POSIXLY_CORRECT' or
'_POSIX_OPTION_ORDER'.
There are two different styles of options: 'short' and 'long'.
Short options are the sort which Unix has known for ages: an option is a
single letter, preceded by a '-'. Short options can be joined together to
save space (and possibly to make silly words): e.g., instead of giving
options '-x -y', a user could write '-xy'. Some short options can have
arguments, which appear after the option letter, either immediately
following, or in the next 'word' (so an option with an argument could be
written as '-o foo' or as '-ofoo'). Note that options with optional arguments
must be written in the second style.
When a short option controls a flag setting, it is sometimes possible to
explicitly turn the flag off, as well as turning it on, (usually to override
default options). This is usually done by using a '+' instead of a '-' to
introduce the option.
Long options, as popularised by the GNU utilities, are given long-ish
memorable names, preceded by a double-dash '--'. Since their names are more
than a single character, long options can't be combined in the same way as
short options. Arguments to long options may be given either in the same
'word', separated from the option name by an equals sign, or in the following
'word'.
Long option names can be abbreviated if necessary, as long as the
abbreviation is unique. This means that options can have sensible and
memorable names but still not require much typing from an experienced user.
Like short options, long options can control flag settings. The options to
manipulate these settings come in pairs: an option of the form '--set-flag'
might set the flag, while an option of the form '--no-set-flag' might clear
it.
It is usual for applications to provide both short and long options with
identical behaviour. Some applications with lots of options may only provide
long options (although they will often be only two or three characters long).
In this case, long options can be preceded with a single '-' character, and
negated by a '+' character.
Finally, some (older) programs accept arguments of the form '-<number>', to
set some numerical parameter, typically a line count of some kind.
|
|
|