git-bash $PATH cannot parse windows directory with

2020-02-06 05:07发布

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.

for example the $PATH outputs:

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

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

6条回答
闹够了就滚
2楼-- · 2020-02-06 05:21

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

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

查看更多
劫难
3楼-- · 2020-02-06 05:32

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:

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.

查看更多
虎瘦雄心在
4楼-- · 2020-02-06 05:37

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

ex. cd My\ Documents

查看更多
冷血范
5楼-- · 2020-02-06 05:39

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.

查看更多
来,给爷笑一个
6楼-- · 2020-02-06 05:44

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

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

same for PATH variable etc.

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

查看更多
萌系小妹纸
7楼-- · 2020-02-06 05:47

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

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 ~/ !

查看更多
登录 后发表回答