506 private links
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?
Why does Windows use backslashes for paths and Unix forward slashes?
– phuclv Commented Aug 13, 2018 at 16:55While 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 Commented Aug 1, 2022 at 20:10@ssokolow UNIX was there with its forward slashes long before MacOS and DOS were created.
– SF. CommentedAug 2, 2022 at 8:13@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 Commented Aug 3, 2022 at 5:31Use 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 Commented Aug 3, 2022 at 16:51
A:
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. //
A:
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.
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 Commented May 26, 2023 at 1:47