Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute commands in git-bash in Windows which are located in a folder with spaces ie "Program Files"?

When I use git bash, from time to time I want to invoke a command which 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.

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.

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 ¬¬

Q. How can I execute commands in git-bash which are located in a folder with spaces?

like image 785
OscarRyz Avatar asked May 17 '12 18:05

OscarRyz


People also ask

How do I run a git bash in a specific folder?

Using Windows Explorer, navigate to any directory you want, type "cmd" in the address bar it will open Windows command prompt in that directory. Along the same lines, if you have the git directory in your path, you can type "git-bash" in the address bar and a Git Shell will open in that directory.

How do I run git bash on Windows?

Git Bash comes included as part of the Git For Windows package. Download and install Git For Windows like other Windows applications. Once downloaded find the included .exe file and open to execute Git Bash.

How do I run an EXE in git bash?

To run a Windows program, enter the path to the program's .exe file in the Bash shell. Remember that your Windows C: drive is available at /mnt/c in Bash. The Bash environment is also case-sensitive, so you have to specify the correct capitalization.


2 Answers

Commands in git-bash accept paths within double quotes

"C:\Program Files\whatever\aCmd.exe"

or back slash for scaping the blank space

c/Program\ Files/whatever/aCmd.exe

Hope it helps!

like image 170
LiA Avatar answered Oct 23 '22 17:10

LiA


Where there are special characters in a file name (spaces, $, parenthesis...) you need to place a backslash ahead of the character so 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:

C:\Program Files (x86)\Notepad++\

Then you would code the path in your bash.rc file as follows:

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:

alias npp=notepad++

which will create a shortcut, allowing you to type npp straight into Bash, instead of having to type out the full program name notepad++ every time.

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.grymoire.com/unix/Quote.html

Hope this helps! :D

like image 22
Howl Huxley Avatar answered Oct 23 '22 16:10

Howl Huxley