Wednesday, July 9, 2008

Writing Unix and Linux Scripts in Windows

I do a lot of cross-platform work these days. I find myself logging into Unix and Linux boxes through a command shell interface and having to run scripts. It's so much easier to create scripts in Windows and then drop them into a share through samba. But there are gotchas.

The main gotcha is the difference between end-of-line sequences for the two platforms. At the following site http://www.boredworkers.com/2006/07/27/converting-windows-and-unix-text-files/ I learned the vi command to replace the cr-lf (Windows) to lf (Linux and unix)

:%s/^M//g

where ^M is created in vi by typing control-v and then return (or enter)