Command Line Options – Use of Equals Sign Between Option Name and Value

options

Just using kubectl as an example, I note that kubectl run --image nginx ... and kubectl run --image=nginx ... both work.

For command-line programs in general, is there a rule about whether an equals sign is allowed/required between the option name and the value?

Best Answer

In general, the implementation of how command-line arguments are interpreted is left completely at the discretion of the programmer.

That said, in many cases, the value of a "long" option (such as is introduced with --option_name) is specified with an = between the option name and the value (i.e. --option_name=value), whereas for single-letter options it is more customary to separate the flag and value with a space, such as -o value, or use no separation at all (as in -oValue).

An example from the man-page of the GNU date utility:

  -d, --date=STRING
          display time described by STRING, not 'now'

  -f, --file=DATEFILE
          like --date; once for each line of DATEFILE

As you can see, the value would be separated by a space from the option switch when using the "short" form (i.e. -d), but by an = when using the "long" form (i.e. --date).

Edit

As pointed out by Stephen Kitt, the GNU coding standard recommends the use of getopt and getopt_long to parse command-line options. The man-page of getopt_long states:

A long option may take a parameter, of the form --arg=param or --arg param.

So, a program using that function will accept both forms.