9

It seems that either a dash - or a slash / will work equally well in a batch file. The two examples below are equaly valid. Which is correct? Does it depend on the operation system? If so how do I determine which to use?

 shutdown -r -m \\server04 -t 01 -f 
 shutdown /r /m \\server04 /t 01 /f 

My goal is to write a batch file that will reach out to several windows severs and reboot them. The end result may also provide for pinging servers and allowing for user supplied choices on which servers to reboot. But my question is intended to define how to best format the code.

I found this related question on SO, which does not really provide an answer when to use one or the other. The question there got a lot of negativity for not being on Superuser. The majority of the opinions suggested that they used dash, but no solid rationale is given for using one over the other.

6
  • 1
    be interesting if anybody knows of any windows commands that require dash
    – barlop
    Apr 25, 2014 at 14:51
  • did you check the command's help manual?
    – NKN
    Apr 25, 2014 at 15:40
  • @NKN, checking the commands help manual would only provide information for that implementation. This question is broader than a single implementation. My particular need is for several windows servers, which may have different versions of windows on them. Also some may wish to reboot non-windows servers at the same time as windows servers. Which is why I am asking if it is "depend on the operation system?" Apr 25, 2014 at 16:02
  • @JamesJenkins Actually it's VERY VERY unlikely that windows uses / in one implementation and dash in another. So if one implementation shows / then assume they are all /.
    – barlop
    Apr 25, 2014 at 18:21
  • -1 it isn't to do with a batch file it is to do with the command(s). Your badly worded question appears to have confused this guy superuser.com/questions/863966/… who titled his question "Running a batch file command with arguments" And he's asking something about the openssl command and whether to use dash or slash. Nothing to do with batch files, but the command itself.
    – barlop
    Jan 13, 2015 at 1:30

3 Answers 3

18

Officially/traditionally in DOS/Windows the command-line switch is signified by a forward slash (/).

Officially/traditionally in practically all other OSs (for example: *nix flavors) they use a dash (-).

This is one of the fundamental differences between the way the OSs are designed and used.

Another (related) one, for example as Daniel B points out in his comment, a forward slash in *nix is for file path separators, where-as DOS/Windows uses backslashes -- another fundamental difference, which enables MS to (continue to) use the forward slash as the switch character.

But it's really up to the programmer to implement how they choose, and DOS/Windows application programmers (including those who work at MS) often include the ability to use either, for ease of use by people coming from other systems, and I'm sure often due to personal preference.

Programmers outside of MS sometimes omit allowing the use of the forward slash at all.

Good blurb:

It’s hard to imagine today, but the original version of Microsoft DOS — that’s MS-DOS 1.0 — didn’t support directories at all when it was released in 1981. Most of the utilities included with DOS were written by IBM, and they used the / character as a “switch” character

...

The different types of slashes here indicate whether you’re specifying an option or a directory path.

Blurb source: Why Windows Uses Backslashes and Everything Else Uses Forward Slashes

4
  • 4
    Well, since forward slash is the path separator on Linux, its use in arguments would be rather inconvenient. It’s also worth noting that a single dash is usually used for short options (single character only) whereas two dashes start a “verbose” argument.
    – Daniel B
    Apr 25, 2014 at 13:41
  • @DanielB That's GNU, not Linux.
    – user
    Apr 25, 2014 at 23:10
  • @MichaelKjörling Regarding the GNU not unix.. the toe eater can call GNU an operating system even without the GNU herd kernel still under development that nobody uses, but everybody else would see GNU as a set of utilities for *nix OSs. There are seem to be two conventions. one one POSIX uses and one GNU uses in addition to that. superuser.com/questions/372203/… see Matt's answer "single dash is implemented by the getopt and is posix standard function, double dash in getopt_long and is a gnu standard."
    – barlop
    Apr 26, 2014 at 16:10
  • @MichaelKjörling and yeh it's not linux, it's some significant commands that are used with linux. (or in stallman's funny perspective, it's an operating system with linux as OS kernel!)
    – barlop
    Apr 26, 2014 at 16:27
0

You should use / for Windows, and - for Unix-like. And don't forget, that parameters of same commands may and will be different in Windows and Unix-like system.

2
  • You write ". And don't forget, that parameters of same commands may and will be different in Windows and Unix-like system" well they wouldn't be the same commands then would they. They'd just be commands with the same name.
    – barlop
    Apr 26, 2014 at 9:05
  • @barlop that's philosophical question en.wikipedia.org/wiki/Ship_of_Theseus
    – Pavlus
    Apr 27, 2014 at 14:09
0

There aren't any commands in windows that only use dash. Even arp can use slash.

Commands that can use dash are based on *nix commands e.g. arp or shutdown.

With shutdown, the cmd help depends on windows version! In XP cmd help shows shutdown -? In Win7 it shows shutdown /?. The MS web help shows it with a dash. But either windows version accepts either.

With arp, the cmd help in XP and 7, and the web help, show it with dash. But they can accept slash.

I don't think MS have ever rewritten a command that took dashes, to only accept slash. And the idea you mention in comments, that you're worried that one implementation might differ from another in using - vs / I don't think so. You'd struggle to find any example of that, I doubt it has ever happened. Microsoft simply don't do that!

If a dash works in one windows version for a command, i'd be surprised if it didn't work in another(for that command). If you ever hear of that happening, e.g. you see an example of it, then you could start concerning yourself with how to know which to use to be compatible across windows versions. Though even then you could go with slash because they all seem to accept it.

2
  • 1
    This is not helpful. shutdown /? & shutdown -? both return the same result set (suggesting / is correct) that differs from Microsoft official documentation (suggesting - is correct) Apr 28, 2014 at 11:47
  • @JamesJenkins Thanks. i've corrected my post. I hadn't checked the web help. Indeed it does differ. BTW you aren't quite right as, in XP cmd help gives - for shutdown, as mentioned in my update.
    – barlop
    Apr 28, 2014 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .