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.
2 Answers
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
- 113,841
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):
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
