windows env: bash\r: 没有那个文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29045140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
env: bash\r: No such file or directory
提问by Brijesh Rakholia
I'm trying to install YouCompleteMe from here.
我正在尝试从这里安装 YouCompleteMe 。
When I execute:
当我执行:
./install.sh --clang-completer
I get this error:
我收到此错误:
env: bash\r: No such file or directory
I don't know whats wrong with environment variables. Here's my bash path:
我不知道环境变量有什么问题。这是我的 bash 路径:
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.
我需要将其更改为 /usr/bash 吗?如果是,那么我该怎么做?我尝试更改 ~/.bashrc 文件,但没有用。
回答by mklement0
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 endingsinstead of the \n
-only line endings bash
expects.
该错误消息表明您正在调用的脚本具有嵌入的\r
字符,这反过来表明它具有Windows 样式的\r\n
行结尾而不是\n
-only 行结尾所bash
期望的。
As a quick fix, you can remove the \r
chars. as follows:
作为快速修复,您可以删除\r
字符。如下:
sed $'s/\r$//' ./install.sh > ./install.Unix.sh
Note: The $'...'
string is an ANSI-C quoted stringsupported 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.
注:该$'...'
字符串是ANSI-C引号字符串支持bash
,ksh
和zsh
。它用于确保\r
在sed
看到脚本之前扩展为实际的 CR 字符,因为并非所有sed
实现本身都支持\r
作为转义序列。
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.
然而,更大的问题是为什么你最终得到了\r\n
-style 文件——很可能,其他文件也受到了影响。
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 outand re-converting to \n
-only line breaks on committing.
也许您正在Windows 上运行Git,其中典型的配置是在检出文件时将 Unix 风格的\n
换行符转换为 Windows 风格的\r\n
换行符,并在提交时重新转换为仅换行符\n
。
While this makes sense for developmenton Windows, it gets in the way of installationscenarioslike these.
虽然这对于Windows上的开发很有意义,但它会妨碍像这样的安装场景。
To make Git check out files with Unix-style file endings on Windows- at least temporarily - use:
为了让Git的检查与Unix风格的文件结尾的文件在Windows上-至少暂时-使用:
git config --global core.autocrlf false
Then run your installation commands involving git clone
again.
然后git clone
再次运行您的安装命令。
To restore Git's behavior later, run git config --global core.autocrlf true
.
要稍后恢复 Git 的行为,请运行git config --global core.autocrlf true
.
回答by Tuan Nguyen
>vim gradlew
:set fileformat=unix
:wq
>./gradlew clean build
回答by Carl Norum
Your file has Windows line endings. Change to Unix line endings.
您的文件具有 Windows 行结尾。更改为 Unix 行结尾。
回答by Michael Harris
Ran into something similar. You can use dos2unix install.sh
to convert the line endings. Multiple files via find [pattern] | xargs dos2unix
遇到了类似的事情。您可以使用dos2unix install.sh
来转换行尾。多个文件通过find [pattern] | xargs dos2unix
回答by igoneHyman
Quick command for converting line ending:
转换行尾的快速命令:
dos2unix thescript.sh
回答by Raghav D
This link helped me solving the issue. https://github.com/tiangolo/uwsgi-nginx-flask-docker/issues/127
这个链接帮助我解决了这个问题。 https://github.com/tiangolo/uwsgi-nginx-flask-docker/issues/127
I edited my .sh file, replacing all CRLF with LF
我编辑了我的 .sh 文件,用 LF 替换了所有 CRLF
回答by luckyhandler
In my case I had a wrong git configuration. The git documentation states:
就我而言,我有一个错误的 git 配置。git 文档指出:
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
如果您在 Windows 上编程并与非 Windows 人员一起工作(反之亦然),您可能会在某些时候遇到行尾问题
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.
我正在使用 Mac OS,并且在我的一个项目中确实遇到了这个问题。为了解决它,我转身autocrlf
到true
这是错误的。
You can check the autocrlf
state of your git configuration like this:
您可以autocrlf
像这样检查git 配置的状态:
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
因此,如果这返回true
并且问题发生在 git 存储库中,您必须将该配置更改为
git config --global core.autocrlf input
on a Mac / Unix system. For Windows only projects you can use
在 Mac/Unix 系统上。对于仅 Windows 的项目,您可以使用
git config --global core.autocrlf false
In my case I deleted the git repository and clone it out again and after that everything worked again as expected.
就我而言,我删除了 git 存储库并再次将其克隆出来,之后一切都按预期工作。
Find out more at https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
在https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration了解更多信息
回答by luckyhandler
In my case I had a wrong git configuration. The git documentation states:
就我而言,我有一个错误的 git 配置。git 文档指出:
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
如果您在 Windows 上编程并与非 Windows 人员一起工作(反之亦然),您可能会在某些时候遇到行尾问题
I'm using Mac OS and I exactly have this issue in one of my projects. To solve it I tuned autocrlf
to true
.
我正在使用 Mac OS,并且在我的一个项目中确实遇到了这个问题。为了解决这个问题我调autocrlf
来true
。
You can check the autocrlf
state of your git configuration like this:
您可以autocrlf
像这样检查git 配置的状态:
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
因此,如果这返回true
并且问题发生在 git 存储库中,您必须将该配置更改为
git config --global core.autocrlf input
which is the correct one for Mac / Unix systems. For Windows only projects you can use
这是 Mac / Unix 系统的正确选择。对于仅 Windows 的项目,您可以使用
git config --global core.autocrlf false
In my case I deleted the git repository and checked it out again and after that everything worked again as expected.
在我的情况下,我删除了 git 存储库并再次检查它,之后一切都按预期工作。
Find out more at https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
在https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration了解更多信息