I’m writing a Ruby script to generates a Unix shell script, but I’m unable to get JRuby to write Unix line breaks on Windows.
I have written a file test.rb which contains:
File.open("test.sh", 'w') do |f|
f.write("#!/bin/sh\n")
f.write("echo hello\n")
end
When I execute it with the command java -jar jruby-complete-1.6.5.jar test.rb then the generated file contains \r\n line breaks instead of \n line breaks.
How can I force JRuby to write a text file with Unix newlines?
I managed to fix it by adding “b” to the parameters of
File.openThe documentation for the IO class says about it the following: