I came across a confusing variation in the understanding what options and arguments are with regard to the syntax of commands.
For instance, I encountered definitions like:
-
command -a -b -c d e f
some differ between
-a -b -c
, call them options or switches andd e f
by calling them arguments. -
command -a -b -c d e f
some, for instance a
bash
manual, call all-a -b -c d e f
arguments and explains, that all of them are accessible from a script by$1 $2 $3 $4 $5 $6
respectively. -
command -a b=c
some call
-a
an option,b
an argument andc
the value, but others mix them like in the first two points, in one variety calling all-a b c
arguments.
Those three versions are only examples for a plethora of different calling varieties, I do not even know how to list them all, but I noticed that for sure there is no fixed naming convention.
Or at least, there is no standardised naming convention I know about, because I came across different random sources, but even among official Linux and GNU affiliated sites or manuals I could met this inconsistency.
Is there a unquestionable official naming scheme I can refer to?
Best Answer
Adapted from the POSIX standard's "Utility Argument Syntax" section:
The utility in the example is named
utility_name
. It is followed by options, option-arguments, and operands.The arguments that consist of
-
characters and single letters or digits, such asa
, are known as options (or, historically, flags). Certain options are followed by an option-argument, as shown with[-c option_argument]
. The arguments following the last options and option-arguments are named operands.The standard also defines "argument" as
All things after the
utility_name
on the command line are the utility's arguments, and they all show up in the positional parameters if it's a shell script. The terms option, option-argument, and operand are more specific names for these arguments on the command line."Flag" and "switch" are common synonyms to "option".
In the case of
-a
andb=c
are arguments,-a
is an option if the utility recognises it as such (theln
utility has no-x
option, so-x
is not an option toln
, strictly speaking, andln -x
would trigger a diagnostic message),b=c
is an option-argument if the-a
option takes an argument, otherwise it's an operand,b
andc
are not options, option-arguments and not operands in themselves.As you notice from my text above, working from the synopsis of a utility (as given by the manual of the utility) would have been easier than trying to decode a generic command typed on the command line. The manual will clearly state what options takes option-arguments and what arguments are operands etc.
To call
c
a "value" is IMHO perfectly ok. It's not a something that is standardised, but very few would misunderstand you if you say "c
is the value given tob
". It would be clear from the context of the utility in question.For example
Anyone who knows about
awk
would say that-v var="d"
means "theawk
variablevar
is assigned the valued
on the command line".