Thursday, May 14, 2009

Bash environment on Windows: This is not Cygwin

Bookmark and Share

If you are a Linux/UNIX guy and are forced to use Windows then you may find this post useful. Linux/Unix guys use windows due to many reasons. One of the reasons is Microsoft Outlook. This is must have for me and there is no application that can take its place in Enterprise environment.

Today, we will try to setup bash environment of Windows XP. If command prompt is launched then it user should able to change his/her default shell to bash shell and should able to execute generally used Unix tools.

There are few software packages that need to be downloaded.

1. Download bash-203.zip and extract it to “c:\bash”

2. Now download Native Win32 ports of some GNU utilities to “c:\temp\UnxUtils”

Now copy all files from “c:\temp\UnxUtils\usr\local\wbin” to “c:\bash”. It should look like this,

BASH directory on windows

Now add “c:\bash” to global PATH environment variable as below,

PATH Environment variable on Windows for bash

On windows, we can also add “HOME” environment variable which will be passed to bash shell.

Once PATH variable includes “c:\bash”, launch Program=>Accessories=>Command Prompt and type in “bash”.

Bash environment is ready on windows. All bash shortcuts will also work as equally as on Linux.

I also know that there could be other ways to get this work done on windows. If you use this or similar technique then let me know your experience in comments below.

4 comments:

Sean Blanton said...

Very useful for the simplicity of the approach and the handy links. I've used bash that comes with MsysGit and Cygwin - both very large distributions.

Sean

Read: http://www.openmakesoftware.com/blogs/seanblanton
Follow: http://www.twitter.com/seanblanton
Connect: http://www.linkedin.com/in/seanblanton

wcarss said...

I just followed these instructions - I'm quite happy to have some additional unix utils on my command line (cat, less, rm) - but I could not get bash itself to work.

It will run fine, but reports "bash: warning: could not find /tmp, please create!" - I tried creating a "tmp" within C:\Users\myusername (where I set my HOME environment to), and also within C:\bash, but this did not stop the error.

Not so bad though, right? Just a warning. Well, actually it's worse: immediately after opening bash, a command like "ls" will display files in the good old fashioned style, then dump this to me: "[sig] C:\bash\bash.exe 1000 (0) call_handler: couldn't get context of main thread, error 998", and hang. After a CTRL+C, you end up with "[sig] bash 1000 (28) call_handler: couldn't get context of main thread, error 998", and now the terminal is entirely nonresponsive.

I'm running 64-bit Win7 Ultimate on an Intel Core2, about 4gb of ram and the rest is unimportant. I'm guessing this is a 64-bit issue or just a "Win7 is different" issue, which is causing some DLL call to fail or return differently and muck things up. If I find a fix I'll report back; I'm also cross-posting this to my own blog.

Thanks for the suggested method to bring bash to Windows!

Wyatt

MikeDW said...

Hi Wyatt, I ran into the same issue with bash. However, I've downloaded another window bash program (http://win-bash.sourceforge.net)and fortunately it works fine. And there is no dll to worry about - it's completely self-contained.

Mike

Earlybotcher said...

the tmp directory should be created in the root of the system:
mkdir /tmp. This worked for me.
Setting Home environment variable got rid of complaint about .bashrc

Post a Comment

Your valuable comments are welcome. (Comments will be moderated.)

 




Technology