#!/usr/bin/env ruby # frozen_string_literal: true # sample-crlf.rb: a Ruby file saved with Windows (CRLF) line endings. # Free sample from 99helpers.com/file-types/rb # # ruby sample-crlf.rb works: Ruby accepts CRLF line endings. With -w it # warns: "shebang line ending with \r may cause problems". # ./sample-crlf.rb fails on macOS and Linux, because the shebang line ends # in an invisible carriage return and the system looks for # a program called "ruby\r": # /usr/bin/env: 'ruby\r': No such file or directory # Fix: convert to LF with dos2unix, or your editor's line-ending setting. data = File.binread(__FILE__) crlf = data.scan("\r\n").size lf_only = data.count("\n") - crlf puts "#{crlf} lines end in CRLF and #{lf_only} in LF alone." puts "Ruby ran this file anyway."