This document is available on the Internet at:  http://urbanmainframe.com/folders/blog/20041021/folders/blog/20041021/

Unix Shell on Windows

Date:  21st October, 2004

Tags:

Born to Run Unix

Our Shapeshifter application servers all run some variant of Unix. Whilst working on the servers I spend most of my time in the BASH shell.

On my Windows XP desktop computer, I spend a large portion of my time using the DOS shell.

The problem is that BASH and DOS have very different command sets. Thus I find myself continually trying to retrieve directory listings in DOS with the "ls" command, I try to delete files with "rm" and I am totally lost without the all-powerful "grep".

Until today. Today I installed UnixKit for Windows...

“a veritable feast of Unix goodness”

Actually, it's wrong to say that I installed UnixKit. There is no installation as such. "Installation" consists of extracting some files from a downloaded zip archive to somewhere on your hard-disk (or LAN). It doesn't get any simpler than that.

UnixKit is a collection of Unix programs that have been compiled to run under the Windows OS. Those programs include:

arc arj bash bunzip2 bzip2 bzip2recover cat chmod cksum cp csplit cut dd df diff du file find fmt fold funzip grep gunzip gzip head join less ln ls md5sum mkdir more mv nano nl paste patch pico pr rm rmdir sed sort split stat tac tail tar touch tr tsort uniq unrar unzip uudecode uuencode vi wc wget zip zsh

As you can see, UnixKit presents a veritable feast of Unix goodness. UnixKit supports pipes and even handles directories with the Unix-like forward-slash ("/") rather than the backslash ("\") of DOS!

In order to take advantage of this pseudo-Unix, we start a DOS shell, navigate to the "\unixkit" directory and enter the simple command "sh". The command prompt changes to "Unix: C:/#" and we're good to go.

The "sh.bat" file that is included with UnixKit generated a couple of errors on my computer. But a slight modification got it running cleanly:

@ECHO OFF
ECHO Starting Unixkit Shell...
SET TERM=vt220
SET EDITOR=nano
SET VISUAL=pico
SET PS1=Unix: %%d#
bin\bash -c 'echo "path `pwd`/bin;$PATH;."' | .\bin\sed s/\//\\/g > pather.bat
call pather.bat
rm pather.bat
cd ..
zsh.exe

All that remained was for me to set up a shortcut icon to "cmd.exe" that would automatically start UnixKit. To do this, I created the shortcut, then edited the "Target" value in its Properties sheet as follows:

%SystemRoot%system32cmd.exe /k "cd \unixkit&&sh.bat"

This tells Windows to start the DOS shell, then change into the "\unixkit" directory before running the "sh.bat" script.

That's all there is to it. It's a simple hack, but one that is going to save me from countless hours of frustration as I make the transition between BASH and DOS.