env: bash\r: No such file or directory [duplicate]
Asked Answered
E

11

208

I'm trying to install YouCompleteMe from here.

When I execute:

./install.sh --clang-completer

I get this error:

env: bash\r: No such file or directory

I don't know what's wrong with environment variables. Here's my bash path:

which bash 
/bin/bash

Do I need to change it to /usr/bash? If yes, then how should I do that? I tried changing ~/.bashrc file, but it didn't work.

Esteresterase answered 14/3, 2015 at 3:33 Comment(3)
If your error was an error, it would probably contain the word "error". It is good that the "bash\r" file was not found because file names can't contain "\".Episodic
A quick fix :) just edit your script in notepad ++ editor and change the EOL conversion to UNIX(LF). I have also faced same issue after changing the EOL conversion to UNIX(LF) it is start working.Medicine
WSL on Windows? See: After installing npm on WSL Ubuntu 20.04 I get the message "/usr/bin/env: ‘bash\r’: No such file or directoryBidden
S
308

The error message suggests that the script you're invoking has embedded \r characters, which in turn suggests that it has Windows-style \r\n line endings (newlines) instead of the \n-only line endings bash expects.

As a quick fix, you can remove the \r chars. as follows:

sed $'s/\r$//' ./install.sh > ./install.Unix.sh

Note: The $'...' string is an ANSI-C quoted string supported in bash, ksh, and zsh. It is used to ensure that the \r expands to an actual CR character before sed sees the script, because not all sed implementations themselves support \r as an escape sequence.

and then run

./install.Unix.sh --clang-completer

However, the larger question is why you've ended up with \r\n-style files - most likely, other files are affected, too.

Perhaps you're running Git on Windows, where a typical configuration is to convert Unix-style \n-only line breaks to Windows-style \r\n line breaks on checking files out and re-converting to \n-only line breaks on committing.

While this somewhat makes sense for development[1] on Windows, it gets in the way of installation scenarios like these.

To make Git check out files with Unix-style file endings on Windows - at least temporarily - use:

git config --global core.autocrlf false

Then run your installation commands involving git clone again.

To restore Git's behavior later, run git config --global core.autocrlf true.


[1] These days, most editors and CLIs on Windows can handle \r\n and \n newlines interchangeably.

Shetrit answered 14/3, 2015 at 3:41 Comment(3)
Had a similar issue with sbt installed through sdkman. For such cases, it's useful to first locate the problematic script with whereis sbt, then apply above command.Kahlil
sed: can't read ./install.sh: No such file or directoryIsolate
Quiet strange I got the same error, but my line endings are fine. I checked it with xxd. This is related to WSL and the solution is in another comment aboveAssegai
L
57

It is happening due to windows line endings. To fix the issue follow below steps

For MAC:

brew install dos2unix # Installs dos2unix Mac
find . -type f -exec dos2unix {} \; # recursively removes windows related stuff

For Linux:

sudo apt-get install -y dos2unix # Installs dos2unix Linux
sudo find . -type f -exec dos2unix {} \; # recursively removes windows related stuff

And make sure your git config is set as follows:

git config --global core.autocrlf input

input makes sure to convert CRLF to LF when writing to the object database

Lint answered 16/9, 2020 at 6:53 Comment(6)
Thanks a lot. I had an issue when running a RN project. react-native run-android wasn't working. Tried all the possible scenarios to fix the issue. Finally this helps to fix that.Redeemable
@salvi I followed above steps in my project folder after deleting node modules but in vscode terminal it works fine but not in WSL2 terminal why so?Mu
This doesn't work for mac, I still get the same messagePrevent
@Prevent make sure your git config is set as per the last stepLint
Actually it should be true, not input. What is input used for? This is how it should be git config --global core.autocrlf truePrevent
@Prevent git config --global core.autocrlf true is recommended for windows as we need to replace CRLF with LF when writing to the object database and then again convert LF to CRLF when writing out into the working directory to retain CRLF on our local.But, if you follow the same for MAC you will be left with CRLF in your working directory. That's why input is used, to only convert CRLF to LF when writing to object database and do NOT do the reverse.Lint
C
52
>vim gradlew
:set fileformat=unix
:wq
>./gradlew clean build
Cauchy answered 27/12, 2018 at 10:39 Comment(0)
F
39

If you are using VS Code, you can switch from CRLF to LF and save the file again. This will replace all CRLF with LF.

enter image description here

Failing answered 20/12, 2021 at 13:45 Comment(3)
This works even in Windows 👍🏻Helical
Tested on Windows and confirmed it worked. Just restart the container in Docker after saving the file and it should work.Sacrarium
This! spent a good few hours trying to various methods and it came down to this on the windows machine.Witherite
D
24

Quick command for converting line ending:

dos2unix thescript.sh
Digitize answered 5/10, 2019 at 5:11 Comment(0)
S
20

Your file has Windows line endings. Change to Unix line endings.

Sparke answered 14/3, 2015 at 3:41 Comment(0)
E
16

Ran into something similar. You can use dos2unix install.sh to convert the line endings. Multiple files via find [pattern] | xargs dos2unix

Earful answered 2/2, 2017 at 18:8 Comment(1)
You could use: find . -type f -exec dos2unix {} \;Halftimbered
P
11

In my case I had a wrong git configuration. The git documentation states:

If you’re programming on Windows and working with people who are not (or vice-versa), you’ll probably run into line-ending issues at some point

I'm using Mac OS and I exactly have this issue in one of my projects. To solve it I turned autocrlf to true which was wrong.

You can check the autocrlf state of your git configuration like this:

git config core.autocrlf

So if this returns true and the problem occurs within a git repository you'll have to change that configuration to

git config --global core.autocrlf input

on a Mac / Unix system. For Windows only projects you can use

git config --global core.autocrlf false

In my case I deleted the git repository and cloned it again and after that everything worked again as expected.

Find out more at https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

Phlox answered 16/5, 2020 at 22:6 Comment(0)
D
2

I used to have this problem when I tried to downgrade flutter

this solved my issue

rm -rf flutter
git config --global core.autocrlf false
git clone [email protected]:flutter/flutter.git
flutter channel stable
Dissyllable answered 2/7, 2021 at 19:22 Comment(0)
T
0

This link helped me solving the issue. https://github.com/tiangolo/uwsgi-nginx-flask-docker/issues/127

I edited my .sh file, replacing all CRLF with LF

Timeout answered 7/5, 2020 at 8:38 Comment(1)
That's a very terrible thing to do. Please refer to the numerous better solutions provided above.Lint
B
0

In my case: This error occurs when I downloaded and unzip the WINDOWS version into MAC

and then added the windows version path to .bash_profile or .zprofile

so the solution for me was to remove the paths from (.bash_profile and .zprofile) then download the mac version by opening the terminal and type:

  1. mkdir src
  2. cd src
  3. git clone https://github.com/flutter/flutter.git -b stable
  4. export PATH="$PATH:pwd/flutter/bin"
  5. flutter doctor
Burck answered 30/1, 2021 at 18:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.