0

I recently switched from using Ubuntu on dual-boot to using it on WSL. I had a bash script that worked perfectly fine on Ubuntu, which I then cloned from a GitHub repo to windows. When I attempt to run the script in WSL I get the following error:

batch.sh: line 2: $'\r': command not found

How do I clone the repo using the windows installation of git such that newline character treatment is compatible with WSL?


Edit: This question was significantly rephrased to more accurately describe the problem.

6
  • 1
    In the Unix/Linux world If there is a carriage return then the line is not blank. May 14, 2020 at 11:38
  • 1
    How did you copy the file from Ubuntu?
    – gronostaj
    May 14, 2020 at 11:41
  • @gronostaj cloned a git repo containing it.
    – MShakeG
    May 14, 2020 at 11:44
  • @MShaikG This isn't a WSL, Windows, or Ubuntu issue... it's a git issue. There are details in your answer that are crucial to this question, and with those details, the way this question is currently worded is no longer factually accurate.
    – JW0914
    May 14, 2020 at 12:51
  • @MShaikG Thank you for adding the Edit line, however this question needs a re-write to make it factually accurate and applicable. The title alone is not relevant to the issue, as this is not an OS issue, but a git issue experienced, as @gronastaj laid out in their answer, due to options chosen during git installation on Windows. It would be to the benefit of factual accuracy to swap out the bulk of the wording in this question with wording similar to that in your answer to make it factually accurate and applicable to what's been experienced.
    – JW0914
    May 14, 2020 at 13:24

2 Answers 2

3

It's not WSL's fault.

When you're installing git on Windows, the installer asks you which newline treatment you'd like it to use. You must have selected "Checkout as CRLF, commit as LF". Thus git inserts extra \r characters in your text files which were not present on Linux (if they were present you'd be getting the same errors).

You can change this settings in .gitconfig file in your home directory (C:\Users\YourUsername). It's called core.autocrlf. Possible values are:

  • true (your current setting)
  • input (checkout as-is, commit LF)
  • false (checkout and commit as-is).
0

I managed to resolve my particular issue. The bash script was copied to Windows from a cloned GitHub repo, however I cloned the repo from cmd. The issue was resolved when I cloned the repo from WSL. Presumably the cause of the problem has to do with the difference in how the 2 operating systems handle/interpret \n and \r characters.

There's definitely a more technical explanation that can be given than mine.

1
  • This isn't a WSL, Windows, or Ubuntu issue... it's a git issue. There are details in this answer that are crucial to your question, and with these details, the way your question is currently worded is no longer factually accurate.
    – JW0914
    May 14, 2020 at 12:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .