git-bash $PATH 无法解析带有空格的 Windows 目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24557224/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:38:53  来源:igfitidea点击:

git-bash $PATH cannot parse windows directory with space

windowsgitpathgit-shell

提问by wyonghao

I would like to use git-bash come with github client on a windows 7 (32bit) machine. Somehow, the git-bash has already learned the $PATHvariables from windows system PATH. However, I found the $PATHin git-bash did not parse the win system PATH with space correctly.

我想在 Windows 7(32 位)机器上使用带有 github 客户端的 git-bash。不知何故,git-bash 已经$PATH从 windows system学习了变量PATH。但是,我发现$PATH在 git-bash 中没有正确解析带有空格的 win 系统路径。

for example the $PATHoutputs:

例如$PATH输出:

"..../c/Program: No such file or directory"

“..../c/Program: 没有这样的文件或目录”

Is there anyway to fix it? where is the git-bash script to construct the $PATHfor git shell? Thanks

反正有办法解决吗?用于构建$PATHfor git shell的 git-bash 脚本在哪里?谢谢

回答by Chris Hermut

Why not using absolute pathinstead of relative pathand if a folder of file name contains a space just use ""(quotes).

为什么不使用绝对path而不是相对path,如果文件名的文件夹包含空格,只需使用""(引号)。

Ex. cd C:/Users/"My Folder"

前任。 cd C:/Users/"My Folder"

回答by Sam Haars

Put a backslash ("\") before the space.

\在空格前放置一个反斜杠 (" ")。

ex. cd My\ Documents

前任。 cd My\ Documents

回答by Seagal82

I am having similar problem.
After some struggle, i put this on the first line in my C:\Program Files\Git\etc\profile:

我有类似的问题。
经过一番挣扎,我把它放在我的第一行C:\Program Files\Git\etc\profile

export HOME=`cygpath -u "\`cygpath -d "$HOMEDRIVE$HOMEPATH"\`"`

export HOME=`cygpath -u "\`cygpath -d "$HOMEDRIVE$HOMEPATH"\`"`

and type command echo $HOMEin bash will come out /c/Users/NAMEXX~1, no more space parsing problem for my $HOMEor ~/!

echo $HOME在 bash 中键入命令将出现/c/Users/NAMEXX~1,我的$HOME~/!没有更多的空间解析问题!

回答by Draco Dynasty

The answer for me was close to that of Seagal82. I added the following line at the start of [PATH_TO_GITBASH_INSTALL]\etc\profile:

对我来说,答案与 Seagal82 接近。我在开头添加了以下行[PATH_TO_GITBASH_INSTALL]\etc\profile

export HOME="/c/Users/Username\ with\ spaces/"

Then I started a new git bash window and all the paths in $PATHusing $HOMEgot replaced with the anti-slashed space and work correctly.

然后,我开始了一个新的Git的bash窗口,并在所有的路径$PATH使用$HOME得到了具有防削减空间和正常工作所取代。

回答by ilyavaio

Basically to confirm what is working: For environment variables use export keyword:

基本上是为了确认什么是有效的:对于环境变量,使用 export 关键字:

export JAVA_HOME="/c/Program Files/Java/jdkxxxxx"

same for PATH variable etc.

PATH 变量等也是如此。

You can put it in your ~/.bashrc . Then, use variables instead of direct string with spaces

你可以把它放在你的 ~/.bashrc 中。然后,使用变量而不是带空格的直接字符串

回答by ihayet

git-bashruns in a Linuxenvironment. As, linux doesn't recognize \ backslashin its directory path, you need to use / forwardslash. Use ""if you directory path contains spaces.

git-bashLinux环境中运行。由于 linux\ backslash在其目录路径中无法识别,因此您需要使用/ forwardslash. ""如果您的目录路径包含空格,请使用。

回答by Steven Arnold

Use the bash declare command -

使用 bash 声明命令 -

$ declare -x PATH="/path with spaces":$PATH