14

Ubuntu has a bash (Bourne Again SHell) whereas Windows has it's proprietary shell. According to my research there is no name for the language used for shell scripting in Windows/Ubuntu. It's just called shell scripting.

Why do Windows & Ubuntu shells understand the same commands such as : ls, mkdir, rmdir, mount and so on?

Is there some sort of lingua franca for shell scripting? If so, please give me more details.

6
  • 9
    See en.wikipedia.org/wiki/List_of_Unix_commands - look for when these commands first appeared, and check when Windows and GNU first appeared. These commands aren't part of bash - they are external utilities, so which shell is used is irrelevant.
    – muru
    Feb 24, 2016 at 15:17
  • 10
    And I'm pretty sure ls is supported by Powershell, not cmd.exe. And that's because the creators of Powershell put in some effort to add aliases for common Unix commands so that Unix users would be more comfortable. technet.microsoft.com/en-us/library/dd347739.aspx
    – muru
    Feb 24, 2016 at 15:18
  • 7
    The Wikipedia article on DOS, might shed some light on this. Quote: "DOS instead ran on Intel 8086 16-bit processors. Starting with MS-DOS 1.28 and PC DOS 2.0 the operating system incorporated various features inspired from Xenix, Microsoft's variant of Unix." So Unix is, up to a point, a forefather to MS-DOS. en.wikipedia.org/wiki/DOS
    – theodorn
    Feb 24, 2016 at 15:37
  • 4
    @muru: In fact, both the Unix and the DOS commands are actually just aliases to the real PowerShell commands, which are named according to a standardized Action-Object structure, composed of a set of also standardized actions and objects. For example, both ls and dir are aliases for Get-ChildItem (which additionally has the alias gci), mkdir and md are actually New-Item (which can actually create much more than just directories, owing to PowerShell's object-based approach), and so on. Feb 25, 2016 at 0:07
  • 2
    Also look at CPM, VMS, JCL.
    – Zan Lynx
    Feb 25, 2016 at 8:31

2 Answers 2

44

The Windows cmd.exe does not support ls, mount, etc., unless you installed these yourself and added them to the %PATH% (via Cygwin, MinGW, Subsystem for Unix-based Applications (SUA) or something else). Powershell does. And that's because Powershell has these as aliases to standard Powershell commands, so that Unix users can be more comfortable. See the list of Compatibility Aliases in Powershell. Windows does have rmdir, mkdir, etc., but these, of course, don't support the same option syntax that you'd find on Ubuntu.

In Ubuntu, these have nothing to do with Bash. They are all external commands. There are standards for such utilities. POSIX is the most notable (see the list of POSIX-mandated utilities), and Linux Standard Base (LSB) is another that's important for Linux systems (which is mostly based on POSIX, but has some additions). The ones on Ubuntu are mostly provided by GNU, and GNU utilities often have more features than the base required by POSIX.

POSIX also defines the shell language that you mentioned (which is substantially different from the one in cmd.exe). It is derived from the Bourne shell's syntax. Bash (now you know what the Bourne again refers to), also from GNU, also adds features on top, but can behave in a POSIX-compliant manner when required. The POSIX language is what you'd expect to get with sh. bash, ksh, ash, dash, zsh all use that language, with enhancements. csh is in a (nightmare) world of its own, and tcsh enhances csh.

To understand a bit more, look into the history of Unix and Unix-like systems. Unix pre-dates Windows by over a decade, and these utilities first appeared in Unix.

Windows was, at one time, POSIX-compliant, since the US government required it for OSes used by government agencies (that's when they added the Services for Unix (SFU), from which came the SUA mentioned in the first paragraph). But that requirement was scrapped, and subsequently, SUA was dropped.

Related:

(Note the common part of these posts - they are all on Unix & Linux, and tagged history - you might find browsing through that tag very informative.)

11
  • 3
    AFAIK, rmdir (along with mkdir and cd / chdir) are native command.com builtins since MS-DOS 2.0 (there was no hierarchy in the DOS file system before)
    – jlliagre
    Feb 24, 2016 at 16:14
  • 1
    rd was a shortcut, md too.
    – jlliagre
    Feb 24, 2016 at 16:51
  • 1
    This is what I've got from reading your answer and skimming through links provided from others: These command/utilities have first appeared in the past on various different systems. Over time most of them have been integrated into Ubuntu and some of them into Windows. Windows however decided to do things their own way and create their own version of these utilities. Over time Windows decided to add aliases to their own shell commands so that linux users can use commands that on the surface appear the same as on their systems but underneath they're translated to windows commands Feb 25, 2016 at 13:13
  • 1
    The POSIX language is what you'd expect to get with sh. bash, ksh, ash, dash, zsh all use that language, with enhancements. csh is in a (nightmare) world of its own, and tcsh enhances csh. Windows did, at one time, obey POSIX, since the US government required it for OSes used by government agencies (that's where the SUA came from). But that requirement was scrapped, and subsequently, SUA was dropped.
    – muru
    Feb 25, 2016 at 13:34
  • 1
    @ShadyProgrammer another U&L post you will find interesting: unix.stackexchange.com/q/145522/70524
    – muru
    Feb 25, 2016 at 13:42
0

Simple:

Linux is a system based on the UNIX model, as invented by Dennis Ritchie and Ken Thompson.

Windows/DOS is a cheap knockoff of a system called CP/M which was popular in the 1970's on those old computers you plugged on a TV, this system in turn was a cheap knockoff of the early UNIX systems from the late 60's / early 70's.

1
  • While there's some truth to your answer, it's way too oversimplified to be useful. (And we used monitors or terminals with CP/M - not TVs ;) ) When I'm trying to figure out some obscure bash or sed command, I sometimes think back to those days when the OS hardly did anything for you, but it was easy to do - and I never ran out of memory on a 64k machine.
    – Joe
    Mar 2, 2016 at 23:13

You must log in to answer this question.

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