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

后端 未结 4 1035
灰色年华
灰色年华 2021-01-12 05:43

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 s

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 06:10

    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++:::...:
    

    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

提交回复
热议问题