Is there a difference between a command line flag and a command line option?

8

4

I am hearing these two terms interchangeably and I am wondering if there is any difference between them, like flags are for one letter options or flags are after a single dash.

yoyo_fun

Posted 2016-04-26T17:18:30.353

Reputation: 1 443

I haven't seen any evidence to support either assertion below re: the "official" distinction between flag & option, which suggests that @Anthon's humble response to the same question over on unix.stackexchange might be more accurate, if less definitive: https://unix.stackexchange.com/questions/285575/whats-the-difference-between-a-flag-an-option-and-an-argument.

– clozach – 2019-05-07T22:17:42.853

Answers

11

You'll probably find "arguments", "options", and "switches" are also often used interchangeably in this context as well.

"Flags" specifically, are Boolean arguments, set by the mere inclusion of the command-line argument, with no additional data needed or allowed for the argument. If you include the argument/option/flag, it counts as "true" and if you exclude it, it counts as "false".

Example Flag-type argument:

command.exe -DeleteFiles

Example of non-flag argument:

command.exe -ServerName my.server.com

More info

Ƭᴇcʜιᴇ007

Posted 2016-04-26T17:18:30.353

Reputation: 103 763

Simple and effective explanation. You could probably even put that 2nd paragraph into the tag wiki for flag, since it has no description currently and that makes it a bit less ambiguous. – Broots Waymb – 2016-04-26T18:06:48.513

1

According to Build Awesome Command-Line Applications in Ruby 2 the main distinction is: a switch doesn't take arguments, while a flag does. Quoting directly from the book (page 15):

enter image description here

Typically, if a switch is in the long-form (for example --foo), which turns “on” some behavior, there is also another switch preceded with no- (for example --no-foo) that turns “off” the behavior.

Finally, long-form flags take their argument via an equal sign, whereas in the short form of a flag, an equal sign is typically not used. For example, the curl command, which makes HTTP requests, provides both short-form and long-form flags to specify an HTTP request method: -X and --request, respectively. The following example invocations show how to properly pass arguments to those flags:

curl -X POST http://www.google.com
curl --request=POST http://www.google.com

mbigras

Posted 2016-04-26T17:18:30.353

Reputation: 202