Maybe you – like me – have learned to know and love the linux bash with its pipes and filters and its standard commands like sed, grep, find, awk, alias, xargs and so on. Maybe you have to do anything with the Windows batch or Windows command shell now. Then you will not only feel like in the stone age, but you’ll feel personally insulted by how ugly, impractical and unusable the Windows tools are.
You’ll long for your precious bash and your beloved grep. You are not alone…. That’s why since 1995 people are working on Cygwin. Cygwin is a bash with a huge lot of commands, usable on Windows. I have been using it now for more than ten years, and there have not been too many working days when I haven’t used it for this or that. I only can recommend it warmly for bash addicts coming to Windows.
To start using it, just download the latest Cygwin installer and run it. You’ll be firing your first find | xargs | grep in a quarter of an hour. It’s that easy.
Though it has some quirks, it can be used quite well as your personal shell on Windows PCs. (I would not recommend to use it on a build server or as part of the software build process. Because of the quirks and because it would be an administration nightmare.)
When it works, it works well. I have not updated one single package of the Cygwin installation on my working PC since 2009…. This week, I had to move the Cygwin to my new working PC. But this is another story.
I’d love to hear from you: Which shell do you use on Windows? Why?
What are the quirks, you are asking?
In short: line endings.
Unix line endings are \n, Windows line endings are \r\n. This leads to a whole lot of problems which have never been solved well by the Cygwin developers. And I assume these problems cannot and will not ever been solved well.
Because of the different line endings you have such strange things as being able to mount a directory in textmode or in binmode.
Some Cygwin commands do different stuff, depending on the mount mode of the stuff. When the stuff comes from a binmode mounted directory, it is treated differently than when it comes from a textmode mounted directory. But not all Cygwin commands do the same. Some treat stuff like this and some like that. And of course, it also depends on the version of the tool. And, as some commands create temp files, your result may also depend on the mount mode of your temp directory.
It may be that cat foo | grep bar results in different line-endings than grep bar foo. And that grep bar foo | awk // gives a third type of line-ending. There even have been versions of Cygwin where the commands also differentiated between different path notations.
All of this binmode/textmode/line-endings stuff is just !$%!$%!$.
And you’ll end up with files having \n as line-endings or even \r\n\n or probably anything that matches [\r\n]+ where they should just always have \r\n. This will happen, when you are using Cygwin in a regular way. Mostly, it is just a call of u2d (unix2dos) or some similar command and the file is correct again.