Home > Software engineering >  WSL: Ways to deal with bash script that was checked out on Windows
WSL: Ways to deal with bash script that was checked out on Windows

Time:08-17

I don't know if I' missing something here, but this is my current situation:

  • GIT Repo checked out on Windows machine
  • Line endings are automatically converted (autocrlf = true)
  • installed WSL with Ubuntu

There are some Bash scripts in this repo that I want to execute via WSL. It doesn't work out-of-the-box due to the auto-converted line endings. So my current solution is to convert the script before execution with dos2unix.

Is there a fancy solution out there to get it working without manually converting the files?

CodePudding user response:

I think what you want is when you do a git pull it should automatically convert them to LF (\n) so you can run the files, and then on commit, you want them to be committed at CRLF (\r\n). Here's what you want:

git config core.autocrlf false

Inside your project .gitattributes file:

* text eol=crlf

Now there are probably only certain file types you want automatically converted. So for example, if they were .sh files, you would modify the .gitattributes file to:

*.sh text eol=crlf
  • Related