Problem: You’re trying to run a bash script embedded in a git repository to provision a vagrant machine and are getting an error that no one else is.
Solution: You’re using a windows host. The default on windows is for git to checkout files using Windows friendly line endings and then save them to the repository using unix line endings. Bash on linux is expecting unix line endings and errors if that expectation is not met.
You’ll need to set your settings for this project and re-checkout the files.
Open a command / “git bash” prompt in your project directory and run:
git config core.autocrlf
This should show you your current settings for this feature of git.
The options are true,input or false.
- true: checkout as windows; check in as unix.
- input: checkout as whatever is in git and check-in as unix.
- false: checkout as whatever and check-in as same.
for this repository I changed my settings to
git config core.autocrlftrue then
git reset --hard
This is does fix the problem but it’s not the best solution for your project.
You should probably have a “.gitattributes” file in your root directory to set this settings explicitly instead of depending on your team to set these up on checkout every time.
* text=auto *.sh text eol=lf *.conf text eol=lf *.bat text eol=crlf
This will inform git to have different defaults for these specific types in this project. Git is good at detecting binary vs text so you don’t have to go crazy listing every type in your project.
See more about .gitattributes in the book of git.