Home

Comparing command shells - BASH, OS X and Windows

While putting this site together I've had time to compare the commands and features of Linux Bash, OS X and the Windows command shell. I therefore thought it might be useful to share my thoughts on how they compare in terms of functionality and ease of use.

First of all the choice of OS for a particular application will always be driven by factors other than how well the command line stacks up. e.g. Scalability, Security and Stability. Bearing that in mind lets look at how the command shells compare.

Functionality

The situation a few years back (in the days of Windows 95 running on top of DOS) was that Unix/Linux had the more complicated but powerful command line interface while Windows provided a simple but limited command line.

As Windows moved to the NT infrastructure, it's command line has been changed and improved out of all recognition. A modern Windows installation with the additional Microsoft Support tools and Resource Kit installed will have just as many commands available as a Linux BASH shell.(1)

This is perhaps best illustrated with an example - the command to copy a file:

Under UNIX there is `cp', `rcp' and `rsync' - together providing 24 options.

Under OS X - there is `cp', `rcp', `rsync', `CpMac', `ditto', `copy' and `install' - around 55 options

MS-DOS - there is COPY - this has just 3 options.

Under Windows NT/XP there is COPY, XCOPY, SCOPY, ROBOCOPY, MCOPY, MTC, FCOPY and PERMCOPY - over 100 options to choose from.

Having multiple commands for the same basic operation is a bad thing - it means a duplication of the same options under each command plus there will be times when all the options you require aren't available in a single command. To be fair things are improving in this area, `rsync' can replace all the functionality of `rcp' and the latest version of ROBOCOPY with over 70 options; makes just about all the other WinNT copy commands obsolete.

Ease of Use

Consistency - the use of consistent letters makes remembering the options available much easier

Some examples

Option to Recurse subfolders:

Unix/Linux:
cp -r or grep -r or rm -r or gzip -r

Windows:
MUNGE /R or RD /S or CACLS /T

Option to display command help:

Linux:
cp --help or grep --help or gzip --help

OS X
cp -h or grep -help or gzip -h

Windows
COPY /? or PING -? or NET HELPMSG message#

Other inconsistencies found in Windows are the error codes (largely undocumented) and inconsistent output text. Often standard_output and standard_error are swapped which makes command redirection something of a guessing game.

Verbosity - support for verbose options improves readability and allows a single command to support more options without running out of letters in the alphabet.

For example in BASH to prompt the user before performing a copy you can do
cp --interactive

Compare this syntax with OS X:
cp -i

or Windows:
COPY /-Y

Availability

Many MS Windows operations require utilities from the Resource Kit or Support Tools. Although these are freely available from Microsoft, to be sure a command will work you have to make sure it's been installed on the machine in question.

Scripting languages

All operating systems can take advantage of scripting languages such as WSH, Python or Perl. In the case of Windows you can install Cygwin and run a full bash shell under win32. The problem with this approach is that there is often patchy support for the newer or more advanced OS features. e.g. Try writing a script with any of these tools that can change the NTFS permissions of a long filename.

For a full UNIX scripting environment that runs natively on MS Windows there is Microsoft / Interix SFU (Services for UNIX) Althought this is fully supported by MS Product Support Services you need to consider the administrative overhead of running Interix SFU itself (previous versions of Interix had a bit of a reputation for buggy behaviour in some areas.)

Summary

The Unix based systems were always going to come out ahead for pure command line scripting ability.

In terms of basic functionality Windows has similar commands doing very similar things, but falls down in areas of interoperability, consistency and ease of use. However in the future Microsoft's Next Generation Shell promised for release in Longhorn may dramatically improve on the current offerings from Microsoft.
Early beta copies of the msh shell (code name monad) are now available at beta.microsoft.com

Notes:
(1) I'm ignoring here any alternative shells and other scripting languages that may be installed on either platform.

(2) The commonality between 16 bit MS-DOS and 32 bit Windows platforms is far from perfect - it's almost impossible to write a batch file of any complexity that will run on both. However there is more consistency than you might expect given the 20 year time difference.

"Beauty is more important in computing than anywhere else in technology because software is so complicated. Beauty is the ultimate defence against complexity" - David Gelernter

Links
microsoft.public.servicesforunix.general
InteropSystems UNIX tools for interix SFU 3.5
AINTX - 'AIX-like' commands for WinNT
DOSEMU - Emulate MS-DOS under Linux (HowTo)
Q234968 - SCOPY made redundant in Windows 2000
In the beginning was the command line - Neal Stephenson

Simon Sheppard, April 2004



Simon Sheppard
SS64.com