1

I am trying to build some code in Linux and I am getting the error:

'\r': command not found 

Now I know this question has been asked in general before and I have already read the answers to them. In this question I am asking for a clarification for my particular situation.

In those questions, the reasons for that error has already been explained: The existence of an invisible character that gets interpreted as a command.

One suggested solution has been to modify the files to eliminate those characters. This solution is not feasible in my case for two reasons:

  1. It is impractical to go and modify all the files involved
  2. It has been expressly ordered to me that I cannot modify the files.

One solution recommended here and here suggest to modify the EOL behavior in Cygwin by setting an option to ignore CRs:

The problem is that this igncr option has so few documentation that I couldn't find details on this. Is this option available for linux systems too?

(For reference I am working on a git bash in windows to manage the repository but I build the code after transferring it to a linux workstation inside a docker container)

The other possible solution I found was this one in which it was suggested to modify the git settings in order to configure Git to not convert line endings on checkout:

How does this config works? In the linked answer it says

git config --global core.autocrlf input

when I do git config --list in my windows machine I get

  core.autocrlf=true

Should I change the config and clone my entire repository again??

I am looking for clarifications on these two possible solutions but any other solution (that does not involve modifying the files) is fine too

Just for reference

I git manage locally a repo on a windows machine. Once finished I transfer the code to a remote linux machine and I build the code there. There is where the problem with \r appears

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • What is `core.autocrlf` on your linux workstation? AIUI it needs to be either `input` or `false`. – Gordon Davisson Jul 06 '21 at 03:40
  • right now, it seems not set. I did `git config --list` and all I got was 4 filter.lfs configurations. I should point out (I know it it weird) that I copy the source file to the WS with scp, so I am not maintaining a repo there – KansaiRobot Jul 06 '21 at 04:17
  • @KansaiRobot : Is there a particular reason why the files in your repo do have a carriage return to mark the line ending? From my experience, most programs in the Windows world can process text files with either LF or CRLF as terminator. – user1934428 Jul 06 '21 at 06:48

1 Answers1

1

First, for reasons explained in "What is the correct core.autocrlf setting I should use?", make sure to add:

git config --global core.autocrlf false

Second:

  • try and fix your partical file eol (dos2unix or other commands), and
  • add in a .gitattributes file a myfile eol=lf directive to force said file to keep the right end-of-line sequence.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250