0

SETUP:

A large repository is cloned via 'git' where line endings are adapted automatically. That is, a bash script checked in under Linux appears under Windows as a file with endings 0D0A instead of only 0A. The policy of checkout cannot be modified.

Any script checked out under Windows appears with 0D0A as line endings. Scripts 'source' other scripts, so converting one script does not suffice. Converting all scripts in the repository is not practical.

PROBLEM:

Window's bash does not run on scripts where the line ending is 0D0A. First idea was bash-0d0a converting before execution:

tmp=$(mktemp)
script=$1
shift
awk 1 RS='\r\n' ORS='\n' $script > $tmp
mv $tmp $script
source $script $@

The adapter 'bash-0d0a', however, does not treat 'source-ed' files from within the file to be treated.

QUESTION:

Would it make sense to do:

export PATH=$(dirname path-to-bash-0d0a):$PATH
mv bash-0d0a bash

Or, is it possible, somehow, to let bash do this directly?

Frank-Rene Schäfer
  • 3,182
  • 27
  • 51
  • 2
    `let bash do this directly?` Modify bash sources to handle dos line endings. But why not remove dos line endings from all files in that git repository? A shell script with dos line endings is invalid, no matter the platform. Why not set `.sh eol=lf` in your `.gitattributes`? And are you sure it's not your git configuration that is changing the files? Check your `core.autocrlf` and `.gitattributes` settings. – KamilCuk Feb 11 '21 at 10:15
  • @Frank-RenaSchäfer : I'm not aware that **any** bash implementation currently supports CRLF-delimited scripts. Of course you can convert them (the typical way would be to use `dos2unix`), but overall, this sounds more like a git configuration question. What git implementation are you using? Perhaps duplicate to [this](https://stackoverflow.com/questions/2517190/how-do-i-force-git-to-use-lf-instead-of-crlf-under-windows) questions? – user1934428 Feb 11 '21 at 14:08
  • @Frank-ReneSchäfer: Just FYI: In our project, I'm using the Cygwin implementation of git and bash, and Github for hosting the project, and don't have any problem with undesired line endings. – user1934428 Feb 11 '21 at 14:10
  • @user1934428: The git environment is where the issue occurs. The fact that bash-es cannot cope with 0xD 0xA, is something that can be discussed separately. – Frank-Rene Schäfer Feb 11 '21 at 19:24

0 Answers0