Why there is a backslash, I bet you haven’t even noticed or even care!

The difference between “\” and “/”

There is something that we have all become familiar with and it wasn’t until I started swapping between using UNIX and MSDos that I even noticed. Look at the URL in your internet browser. Notice its http://www.cmx.co.uk/blog/. The slashes lean forward like this / whereas if you look at a Windows location then its C:\windows\system32\. The \ doesn’t even exist on golfball or other typewriters – Do you remember them?

If you are a Unix geek like we are then you know the answer, maybe you don’t care but for the rest of you here is the answer. The quick one is \ is for MsDos which is behind Windows in all it’s guises. The other is for UNIX which runs many things including the internet, TV’s, mobile phones, routers and so much more, it’s amazing. (read our post a few weeks ago to find out more).

It all stems from Microsoft’s relationship with IBM. When MSDos Version 1 came out there were only floppy disks A & B.

Many of the DOS utilities were written by IBM, and they used the “/” character as the “switch” character. The “switch” character is the extra character that tells the utility which options to use.

Although on UNIX it was the “-” character but most early DEC operating systems used “/”. As several of the original MS-DOS developers were old DEC developers it’s possible that they carried it forward.

The fact that the “/” character conflicted with the path character of other relatively popular operating systems weren’t particularly relevant to the original developers – because DOS didn’t support directories, just files in a single root directory.

Then along came DOS 2.0 tied to the PC/XT, whose major feature was a 10 Mb hard disk. IBM asked the Microsoft to add support for hard disks, and the MS-DOS developers took this as an opportunity to add support for modern file Application Programming Interface’s (API) – they added a whole series of handle based APIs to the system (DOS 1.0 relied on an application controlled structure called an File Control Block (FCB). They also had to add support for hierarchical paths or directories as we know them.

Now historically there have been a number of different mechanisms for providing hierarchical paths. UNIX defines hierarchical paths with a simple hierarchy rooted at “/” – in UNIX naming hierarchy, there’s no way of differentiating between devices, files and directories, etc. (This isn’t bad when you get used to it by the way, its just how it works.

For MS-DOS 2.0, the designers of DOS chose a hybrid version – they already had support for drive letters from DOS 1.0, so they needed to continue using that. And they chose to use the UNIX style method of specifying a hierarchy – instead of calling the directory out in the filename, they simply made the directory and filename indistinguishable parts of the path.

But there was a problem. They couldn’t use the UNIX form of path separator of “/”, because the “/” was being used for the switch character.

So what were they to do? They could have used the “.” character like the DEC machines, but the “.” character was being used to differentiate between file and extension. So they chose the next best thing – the “\” character, which was visually similar to the “/” character.

And that’s how the “\” character was chosen.

Here’s a little known secret about MS-DOS. The DOS developers weren’t particularly happy about this state of affairs – heck, they all used XENIX (Microsoft’s version of UNIX) machines for e-mail and stuff, so they were familiar with the UNIX command semantics. So they coded the OS to accept either “/” or “\” character as the path character (this continues today, – try typing “notepad c:/boot.ini” on an XP machine.

They then went one step further, they added an undocumented system call to change the switch character and updated the utilities to respect this flag.

Then they went one stage further and finished the scenario; they added a config.sys option, SWITCHAR= that would let you set the switch character to “-“.

Which flipped MS-DOS into a UNIX style system where command lines used “-switch”, and paths were / delimited.

I don’t know the fate of the switchar API, it’s been long gone for many years now.

So that’s why the path character is “\”. It’s because “/” was taken.

Its also why when you use the internet where virtually everything is run by UNIX the / appears but your computer thinks of it as \.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *