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
git-bash $PATH cannot parse windows directory with space
提问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 $PATH
variables from windows system PATH
. However, I found the $PATH
in 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 $PATH
outputs:
例如$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 $PATH
for git shell?
Thanks
反正有办法解决吗?用于构建$PATH
for git shell的 git-bash 脚本在哪里?谢谢
回答by Chris Hermut
Why not using absolute path
instead of relative path
and 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 $HOME
in bash will come out /c/Users/NAMEXX~1
, no more space parsing problem for my $HOME
or ~/
!
并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 $PATH
using $HOME
got 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-bash
runs in a Linux
environment. As, linux doesn't recognize \ backslash
in its directory path, you need to use / forwardslash
. Use ""
if you directory path contains spaces.
git-bash
在Linux
环境中运行。由于 linux\ backslash
在其目录路径中无法识别,因此您需要使用/ forwardslash
. ""
如果您的目录路径包含空格,请使用。
回答by Steven Arnold
Use the bash declare command -
使用 bash 声明命令 -
$ declare -x PATH="/path with spaces":$PATH