Are their any conventions (either written or just generally understood) for when to use a forward slash (/) or a hyphen (-) when reading arguments/flags from a command line?
C:\> myprogram.exe -a
C:\> myprogram.exe /a
The two seem to be interchangeable in my experience, but I haven't used enough command line tools to say I've spotted any rules or patterns.
Is there a good reason that either of them are used at all? Could I theoretically use an asterisk (*) if I wanted to?
The forward slash (or simply slash) character (/) is the divide symbol in programming and on calculator keyboards. For example, 10 / 7 means 10 divided by 7. The slash is also often used in command line syntax to indicate a switch. For example, in the DOS/Windows Xcopy statement xcopy *.
The default is standard input. If no file is specified or if the - (hyphen) is specified as the last file name, the hyphen command reads standard input. The hyphen command can be used as a filter. Note: The hyphen command cannot read hyphenated words that are italic or underlined.
Flags modify the operation of a command and are sometimes called options. A flag is set off by spaces or tabs and usually starts with a dash (-). Exceptions are ps, tar, and ar, which do not require a dash in front of some of the flags. For example, in the following command: ls -a -F.
Use a double backslash as the escape character for backslash.
You can (theoretically) use whatever you want, as the parameters are just strings passed to your command-line program.
Windows convention seems to prefer the use of the forward slash ipconfig /all
, though there are programs that take a hyphen gacutil -i
or even a sort-of environment variable syntax setup SKUUPGRADE=1
.
*Nix convention seems to prefer the hyphen -v
for single-letter parameters, and double hyphen --verbose
for multi-letter parameters.
I tend to prefer hyphens, as they are more OS-agnostic (forward slashes are path delimiters in some OSes) and used in more modern Windows apps (nuget, for example).
Edit:
This would be a good place to recommend a library that does .NET command-line argument parsing: http://commandline.codeplex.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With