Friday, October 17, 2008

Curious end-of-line conversion behavior between DOS and Cygwin

I'm working on a Ruby script that generates shell scripts and batch files. This is similar to the work using ERB like I posted about earlier. Since my desktop is Windows, and the shell script will be run on Linux, I need to worry about end of line characters. Specifically, I need to convert \r\n to \n. I thought this would be straightforward enough to write in Ruby: just use the gsub command, right?



Well, after running my script, I ran od -c to check my results. Unfortunately, it doesn't work when you run the script in DOS. So, since I have Cygwin installed, I changed my script to:



Checking my results, I see that this worked correctly when running in DOS. Then, I checked my results when running the first script in a Cygwin shell, and that worked correctly too.

So, this behavior all seems a little strange to me, but now I know.

No comments: