Oracle – for when it was like that when you got there

Main menu

Post navigation

Windows Bashing…with Cygwin

I was in Wales last week, land of my girlfriend ( yes, I have got one, try not to look so shocked).
Wales, land of story and legend….where the rain goes for it’s summer holidays.

Stepping gingerly between the puddles in picturesque ( albeit, soggy) Laugharne, we spent an instructive ( and mainly dry) hour or so at the boathouse once occupied by Dylan Thomas. In the course of this cultural interlude, I learned that the Great Man’s last words were “ I’ve had 18 straight whiskys. I think that might be the record.”

Hmmm, I wonder if he’d been trying to write a Windows batch script ?

Whatever the merits of Windows in terms of it’s ubiquity, one undeniable fact is that the facilities provided for batch scripting on the command line are stone-age compared to those in Unix.
This is something I’ve often reflected on, usually when confronted with a problem that requires a bit more than a simple for loop.

Help is at hand however, in the form of Cygwin – a toolset which enables you to more-or-less run a bash shell on Windows. Sounds good to me. Let’s have a look….

Installation

Downloading and Installing Cygwin is fairly straightforward.
Go to www.cygwin.com and click the “Install or Update Now” link, select a mirror site and away we go.

An installation program ( setup.exe) is downloaded first. When you run this you then get the option to choose which packages you want to install. For the purposes of this exercise, I just accepted the defaults.

Running Cygwin

If you’ve checked the box to create a desktop icon, you can run by clicking that. Otherwise just going to the start menu and looking under Programs \ Cygwin \ Cygwin Bash Shell will have the same effect.

Oh look, a $ prompt. On Windows. Intruiging.
In honour of the great man, let’s deal with the exestential questions first – who am I ? where am I ? what am I ?

Incidentally, your cygwin home directory on Windows is under c:\cygwin\home\your_user.
Setting command line recall works fine :

$ set -o vi

However, vi itself isn’t included in the default install. Not that this is a big problem. One of the benefits of Cygwin is that you can mix and match linux and windows commands :

$ notepad wisdom.sh
If the file doesn’t exist in this directory, Notepad will ask if you want to create it.

The $PATH variable will include everything that’s in your Windows PATH environment variable.
So, what if you’d rather use TextPad than Notepad for editing. Well, we could try just adding it to the $PATH “linux” environment variable :

export PATH=$PATH;cygdrive/c/”Program Files”/”TextPad 5”

This doesn’t quite do the trick. When you try to invoke TextPad, you get :

bash: TextPad: command not found

To do this, you need to add it to the Windows PATH environment variable itself from the Windows Start Menu (Control Panel / System / Advanced system settings ). Click the Environment Variables button and add the following to the PATH :;c:\Program Files\ TextPad 5

Obviously, you’d need to change this to the path for your TextPad installaion, if different.
If we try again now :

$ textpad wisdom.sh

The file is opened in TextPad.
It’s worth noting that Windows commands seem not to be case sensitive, even when launching from the $ prompt.

Now to have a look at some other files on my C drive.
I’ve created a directory C:\my_cygtest_dir and put some files there.

To finish off this whistle-stop tour, I’ve delved into the dim and distant past for a shell script which is close to my heart.
Many years ago, when the Millenium Bug was still a source of anxiety to IT Managers the world over ( and the source of a nice little nest egg for innumerable COBOL programmers), I was a DBA.

As a matter of course, I’d have the Production Databases alert log tailed in a Terminal window on the desktop. Moving from Unix to VMS it was still possible to do this. On Windows it was sadly impossible.
Let’s see if Cygwin can finally bring this functionality to me :

One thought on “Windows Bashing…with Cygwin”

I’ve used cygwin for a while now and thought I’d leave a tip… I’ve never liked the command window that comes with Windows, and bash makes use of the same be default. To replace it, you can download a program called PuTTYcyg hosted on google code:

This is a modified version of PuTTY, so it has all of PuTTY’s features, but it adds a feature to connect to a local cygwin terminal. You can use PuTTY to connect to localhost, but then you have problem when launching GUI programs as they no longer know where to display since you’re technically connected over the network (through the loopback interface). PuTTYcyg solves that problem without taking away any of the power that cygwin gives you.