如何在 Windows 中的 git-bash 中执行命令,这些命令位于带有空格的文件夹中,即“程序文件”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10641458/
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
How can I execute commands in git-bash in windows which are located in a folder with spaces ie "Program Files"?
提问by OscarRyz
When I use git bash, from time to time I want to invoke a command wich is on my $PATH
( well actually on my %PATH%
) but if the command resides somewhere in a folder with spaces on it, it fails to run.
当我使用 git bash 时,我不时想调用我$PATH
(实际上在我的%PATH%
)上的命令,但如果该命令驻留在文件夹中的某处,上面有空格,则它无法运行。
For instance if the program is on C:\Program Files\whatever\aCmd.exe
and I type aCmd
on bash, it says "Program" is not a valid program and such.
例如,如果程序打开C:\Program Files\whatever\aCmd.exe
并且我aCmd
在 bash 上输入,它会说“程序”不是一个有效的程序等等。
What I did was to re-install the program in a folder without spaces, but recently my coworkers are starting to leave git-gui and are using git-bash and the recurrent question is "How do I execute aCmd" and when I tell them to re-install it they go like ??
我所做的是在一个没有空格的文件夹中重新安装程序,但最近我的同事开始离开 git-gui 并使用 git-bash 并且反复出现的问题是“我如何执行 aCmd”以及何时告诉他们重新安装它,他们会喜欢吗??
Q. How can I execute commands in git-bash which are located in a folder with spaces?
问:如何在 git-bash 中执行位于带有空格的文件夹中的命令?
回答by RRUZ
Just put the command to execute between double quotes, like so
只需将要执行的命令放在双引号之间,就像这样
"C:\Program Files\whatever\aCmd.exe"
回答by Lefan
To reach the directory which has the spaces in it's path you just need to wrap the whole path with quotes. It should look like this:
要到达路径中有空格的目录,您只需要用引号将整个路径括起来。它应该是这样的:
cd "/c/Some Folder/Some Other Folder/"
回答by Howl Huxley
Where there are special charactersin a file name (spaces, $, parenthesis...) you need to place a backslash ahead of the characterso that it reads it as is.
如果文件名中有特殊字符(空格、$、括号...),您需要在字符前放置一个反斜杠,以便它按原样读取。
For example, if you want to run the program notepad++.exe straight from Bash and need to direct the path to:
例如,如果您想直接从 Bash 运行程序 notepad++.exe 并且需要将路径指向:
C:\Program Files (x86)\Notepad++\
Then you would code the path in your bash.rc file as follows:
然后,您将在 bash.rc 文件中对路径进行编码,如下所示:
export PATH=$PATH:/c/Program\ Files\ \(x86\)/Notepad++:<path2>:<path3>:...<pathn>:
Note the backslashes leading the spaces and parentheses.
请注意引导空格和括号的反斜杠。
You can even add an additional line on the next line of your bash.rc file:
您甚至可以在 bash.rc 文件的下一行添加额外的行:
alias npp=notepad++
which will create a shortcut, allowing you to type nppstraight into Bash, instead of having to type out the full program name notepad++every time.
这将创建一个快捷方式,允许您直接在 Bash 中键入npp,而不必每次都键入完整的程序名称notepad++。
I'm a total noob, just started coding 4 days ago, though I found for this problem the best website was the following: http://www.grymtheitroade.com/unix/Quote.html
我是个菜鸟,4 天前才开始编码,虽然我发现这个问题最好的网站如下:http: //www.grymtheitroade.com/unix/Quote.html
Hope this helps! :D
希望这可以帮助!:D
回答by LiA
Commands in git-bash accept paths within double quotes
git-bash 中的命令接受双引号内的路径
"C:\Program Files\whatever\aCmd.exe"
"C:\Program Files\whatever\aCmd.exe"
or back slash for scaping the blank space
或反斜杠用于避开空格
c/Program\ Files/whatever/aCmd.exe
c/Program\ Files/whatever/aCmd.exe
Hope it helps!
希望能帮助到你!