26

MS-DOS and derived systems use backslash \ for path separator and slash / for command parameters. Unix and a number of other systems used slash / for paths and backslash \ for escaping special characters. And to this day this discrepancy causes countless woes to people working on cross-compilers, cross-platform tools, things that have to take network paths or URLs as well as file paths, and other stuff that you'd never imagine to suffer from this.

Why? What are the origins of this difference? Who's to blame and what's their excuse?

user3840170
  • 23,072
  • 4
  • 91
  • 150
SF.
  • 7,095
  • 7
  • 30
  • 58
  • 3
    While your question is perfectly reasonable, your phrasing seems to imply that you think the UNIX approach was already a de facto standard and MS-DOS was unique in deviating from it. See, as a counter-example, how the Macintosh OS used : as its path separator until MacOS X introduced POSIX APIs. This question goes into the history of that decision and answers point to : and . as path separators predating UNIX's use of /. – ssokolow Aug 01 '22 at 20:10
  • @ssokolow UNIX was there with its forward slashes long before MacOS and DOS were created. – SF. Aug 02 '22 at 08:13
  • 1
    @SF. And, as the answer phuclv linked says, DOS got it from CP/M, which got it from VMS. I don't know why VMS chose \ when UNIX chose / seven years before VMS's first release (going by Wikipedia dates), but it wasn't a settled thing. Other designs were using : and . in the mid-60s, half a decade before UNIX decided on /, and UNIX broke from Multics's > because they wanted to use it for shell piping. – ssokolow Aug 03 '22 at 05:31
  • Use of UNIX back then wasn't nearly as ubiquitous as it is today. Almost all of industry and many schools used manufacturer-written and -supplied operating systems, especially from DEC. And within the more well-known CS schools (not that it was called "CS" then) there was also a lot of use of homegrown OSes. So the influence of UNIX wasn't as pronounced as it is today, as well - that took many years to develop. – davidbak Aug 03 '22 at 16:51
  • @davidbak In the era of VMS and Multics - absolutely, yes. In the era of DOS 2.0 and MacOS - much less so. – SF. Aug 04 '22 at 09:27

2 Answers2

25

PC/MS-DOS 1 used the slash (/) as the command line switch indicator (like DEC's RSX11 and DG's RTOS before), so when DOS 2.0 introduced subdirectories, they did need a new one. Backslash (\) came somewhat natural - at least on US keyboards.


With 2.0 IBM/Microsoft also tried to reverse that decision and introduce a syscall (INT 21h function 3700h and 3701h) and a CONFIG.SYS option (SWITCHAR=) to set a different switch indicator. All manufacturer supplied commands would obey that new char. Set to a hyphen (-) would make the syntax more like Unix.

In fact, in paths, the OS didn't care. All dedicated path names, like in syscalls, can be written with either slash. It's only within the command line scan of each command, that simple slashes get interpreted as switch indicators. The idea was that people could/should migrate to a Unix-like style, but that didn't catch on.

With DOS 3.0 the SWITCHAR= option got removed fom CONFIG.SYS, but the syscalls are still availabe up to today.

Raffzahn
  • 222,541
  • 22
  • 631
  • 918
  • 5
    Re the SWITCHAR syscalls, DOS 4 ignored them, and from DOS 5 onwards / is hard-coded (so the syscall still works, but it always returns /). There are several TSRs which restore functioning syscalls, and alternative command processors which honour them (e.g. 4DOS, IIRC). The use of / was indeed based on the DEC operating systems (at least, that’s what The MS-DOS Encyclopedia says). – Stephen Kitt Sep 09 '17 at 13:28
  • I always assumed that the origin of MSDOS use of / for switches was because the origin of MSDOS was SCP's 86-DOS aka QDOS, that Microsoft bought from SCP to create PCDOS for IBM. Because SCP created QDOS as a 8086 "clone" of CP/M and CP/M used / as the switch character (and it was modeled after DEC operating systems). So the indirect origin is DEC with CP/M in between... – mannaggia Sep 09 '17 at 21:12
  • @mannaggia Nop. It is true, that QDOS/S-DOS was modeled after CP/M-80, but CP/M didn't use a switch char at all. Options for a command where usually given in square brackets between the command name and parameters. Example DIR [USER=ALL,DRIVE=ALL] *.ASM to list all assembler sources of all users on all drives. That is unless the command had some syntax of it's own ... and then there was PIP with a weired syntax and options after each parameter, like PIP LPT:=SOURCE.ASM[NT8U] to print a file with line numbers and tab expansion in all uppercase :)) – Raffzahn Sep 09 '17 at 21:44
  • 1
    @Raffzahn wow my memory of CP/M is not as good as I thought... though I used it in school at the same time as RSTS/E and DCL and I guess it's all merged... – mannaggia Sep 10 '17 at 01:58
  • 1
    @mannaggia - I also have memories of CP/M that disagree here. But I think what's happening here is that after official CP/M-80 development stagnated, 3rd party add-ons may have extended or replaced the shell with more DOS-like versions. This summary of CP/M 3 commands dates from 1984, but the era I was using CP/M in was closer to 1988, and it may well have been a substantially different dialect by then. – Jules Sep 10 '17 at 04:22
  • @Jules CCP replacements usually focused on speed (there was a huge hype about using Z80 instructions - not that a user could feel any difference) and handline, but AFAIK they kept the syntax to not break existig scrpts/user knowledge. The ZCPR series might have been the most wiedespread. THen again, I wouldn't be surprised about many shells/IDEs that used CP/M as mere disk handler. – Raffzahn Sep 10 '17 at 08:58
  • 1
    Just because, here's Larry Osterman of Microsoft's recollections on the issue which are congruent with yours. (Looks like his blog post's title got munged through various blogging platform transitions.) – Dranon Sep 11 '17 at 02:22
  • 2
    ...and according to this video by VWestlife, MS-DOS 2.0 was originally intended to be a middle-ground in a migration pyramid between MS-DOS and XENIX named XEDOS. Among other things, that helps to explain why MS-DOS 2.0 introduced APIs that enabled more UNIX-like and less CP/M-like approaches to things like I/O. – ssokolow Aug 01 '22 at 20:04
  • 1
    I find it funny in retrospect that the OS-level acceptance of forward slashes as path separators was not widely known by programmers, as evidenced by the widespread use of backslashes within include directives for MS-DOS-targeted C programs. – supercat Aug 01 '22 at 20:20
  • When you have some commands using - and / as keyword indicators, \ makes a lot of sense. I have often been caught out on systems where you sometimes need =, sometimes : and sometimes space to separate the keyword from the parameter. – cup Aug 02 '22 at 13:32
11

The README.txt file in the MS-DOS 2.0 source code, which was apparently intended to guide OEMs on how to build custom DOS builds for their hardware, indicates that the decision to use backslash was requested by IBM: Microsoft had been originally intending to use forward slash, and the change happened late in the development process. This is probably why the kernel ended up supporting the use of either character -- it was, presumably, too late to change over fully.

The user manual contains some significant errors. Most of these are due to last minute changes to achieve a greater degree of compatibility with IBM's implementation of MS-DOS (PC DOS). This includes the use of "\" instead of "/" as the path separator, and "/" instead of "-" as the switch character.

Jules
  • 12,898
  • 2
  • 42
  • 65
  • 2
    This is true, but very widely misinterpreted – the forward slash as an option character did not come from IBM, IBM's own operating systems (mainframe and minicomputer) never used that syntax. What IBM objected to, was Microsoft's proposal in DOS 2.0 to change it from slash to dash – IBM cared about backward compatibility. But IBM wouldn't have had a problem if Microsoft had made it dash all along, starting with DOS 1.0; IBM didn't care what the syntax was in the initial version, but they didn't want it changed in a subsequent. – Simon Kissane May 26 '23 at 01:47