windows - 环境 : bash\r: No such file or directory

标签 windows git bash line-endings core.autocrlf

<分区>

我正在尝试从 here 安装 YouCompleteMe .

当我执行时:

./install.sh --clang-completer

我收到这个错误:

env: bash\r: No such file or directory

不知道环境变量有什么问题。这是我的 bash 路径:

which bash 
/bin/bash

我需要把它改成/usr/bash吗?如果是,那我该怎么做?我尝试更改 ~/.bashrc 文件,但没有成功。

最佳答案

错误消息表明您正在调用的脚本嵌入了\r 字符,这反过来表明它具有Windows 风格的\r\n 行结尾 而不是 \n 仅行结尾 bash 期望。

作为快速修复,您可以删除\r 字符。如下:

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

注意:$'...' 字符串是 ANSI-C quoted stringbashkshzsh 中受支持。它用于确保 \rsed 看到脚本之前扩展为实际的 CR 字符,因为并非所有 sed 实现本身都支持 \r 作为转义序列。

然后运行

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

但是,更大的问题是为什么您最终得到的是 \r\n 样式的文件 - 很可能其他文件也会受到影响。

也许您在 Windows 上运行 Git,其中典型配置是将 Unix 风格的 \n-only 换行符转换为 Windows 风格的 \r\n checkout 文件 并重新转换为 \n 时换行 - 仅在提交 时换行.

虽然这对 Windows 上的开发有意义,但它妨碍了像这样的安装场景 .

让 Git 在 Windows 上 check out 具有 Unix 风格文件结尾的文件 - 至少暂时 - 使用:

git config --global core.autocrlf false

然后再次运行涉及 git clone 的安装命令。

要稍后恢复 Git 的行为,请运行 git config --global core.autocrlf true

关于windows - 环境 : bash\r: No such file or directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29045140/

相关文章:

linux - awk/sed/grep命令比较三个文件的内容

linux - 根据特定字符串将一个文件的内容插入到另一个文件中

ruby - Ansicon 使我的 ruby​​ Windows 8 崩溃

windows - 批处理文件 : How to leave the console window open

c - 在 Windows 上显示带有自定义按钮标题的警报?

Git 推送到远程分支

windows - 从 Inno Setup 创建受限用户

ruby-on-rails - 忽略git中的本地配置文件

git - 升级到 GIT bash 2.8.2 后,无法运行 sqlite3

linux - 有没有办法在 ssh 中运行本地 bash 函数