5

When I execute any rails command in my project, I'm receiving this warning:

/home/vagrant/.rvm/rubies/ruby-2.5.3/bin/ruby: warning: shebang line ending with \r may cause problems

I tried to install another Ruby version, but the warning is the same. I'm using the same Ubuntu version of the developer.

Rodrigo Corrêa
  • 51
  • 1
  • 1
  • 2
  • _"line ending with \r"_ – seems like your code has Windows line endings, i.e. `\r\n`. Use Unix line endings instead, i.e. `\n`. – Stefan Jan 21 '19 at 09:40
  • @Stefan I’d say it’s rather Macintosh legacy. Win lines do indeed _end with `\n`_, despite there is `\r` before it. – Aleksei Matiushkin Jan 21 '19 at 09:53
  • 1
    @AlekseiMatiushkin: The warning is badly worded. The shebang line is terminated with `\n`. If there is a Windows line ending, then the last character that is *part of the shebang line*, i.e. the last character *before the terminating `\n`* will be `\r`. This will still be interpreted as part of the interpreter name by at least some operating systems, so it will actually search for an interpreter executable named `ruby\r`, which it obviously won't find. So, the warning message considers the last character before the terminator as the "line ending" and the terminator not part of the line. – Jörg W Mittag Jan 21 '19 at 11:36
  • The corresponding method [`warn_cr_in_shebang`](https://github.com/ruby/ruby/blob/v2_6_0/ruby.c#L1871-L1876) actually checks for `\r\n`. I've opened a [PR](https://github.com/ruby/ruby/pull/2073) to reword the message. – Stefan Jan 21 '19 at 11:57

1 Answers1

1

You have a Windows line ending in your file ('\r\n') instead of a unix line ending ('\n'). So the shell tries to get the first line, up to and excluding the first \n, and finds that the line ends with \r.

There are several ways to avoid this issues:

  1. With git, automatically: git config --global core.autocrlf true (see https://help.github.com/articles/dealing-with-line-endings/ and How to change line-ending settings)

  2. With os-level tools: dos2unix (use your OS tools to install it)

  3. Editors + editorconfig file: Check https://editorconfig.org/#file-format-details to see how you can set the end_of_line config, and let your editor do the rest.

rewritten
  • 15,994
  • 2
  • 42
  • 49