Sonny
Sonny

Reputation: 186

Windows Git Bash Whitespace Alias Issue

This might be an issue with Git Bash for Windows.

I am trying to create an alias with parameters to enter some workspace to the specific project directories. However, it seems to have some whitespace issues for Visual Studio Project directories. I tried to double quote the variable, but the error output is rather ambiguous because copying the the cd output works on the bash window.

VS="/c/Users/name/Documents/Visual\ Studio\ 2015/Projects"
alias wkp='function _b(){ cd "'${VS}'"/$1; };_b'

It outputs

bash: cd: /c/Users/name/Documents/Visual\ Studio\ 2015/Projects/: No such file or directory

Working on a regular alias it will be fine, but I will need to cd again into the specific project directory.

alias workp='cd /c/Users/name/Documents/Visual\ Studio\ 2015/Projects'

Is there a reason why whitespaces with backslash and double quote in the parameter won't work for bash functions?

Previous relevant questions Make a Bash alias that takes a parameter? How to pass command line arguments to a shell alias?

Upvotes: 3

Views: 1471

Answers (2)

vaughan
vaughan

Reputation: 7475

I had to use:

alias devenv=\""/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/devenv.exe\""

or else I got

bash: syntax error near unexpected token `('

Upvotes: 0

Sonny
Sonny

Reputation: 186

I found the answer to my question. I needed to remove the backslash in this case.

VS="/c/Users/name/Documents/Visual\ Studio\ 2015/Projects"

VS="/c/Users/name/Documents/Visual Studio 2015/Projects"

It seems cd will take the double quote completely and parse whitespace without needing to use the backslash as an escape.

Upvotes: 1

Related Questions