How do I pass a path with spaces to WSL for Windows Terminal
It's a bit non-intuitive, and just as undocumented as the ~
option, but wsl --cd
sounds like what you are looking for. It actually takes a Windows path spec, not the WSL/Linux form. So:
wsl --cd "C:\Users\My User\repos"
If you are using the Windows Terminal Settings UI, then it will automatically provide the proper quoting for you in the settings.json
, which is:
{
"commandline": "wsl --cd \"C:\\Users\\My User\\repos"",
"name": "Profile Name"
}
And just for fun, here's an alternative, hacky method that you really shouldn't ever need to use, since the --cd
option is the non-hacky, better way:
wsl --exec bash -c "cd /mnt/c/Users/My\ User/repos; exec bash"
While it's not the best option for this particular case, it does demonstrate the ability to edit the environment (PWD
in this case) before exec'ing a shell. That can be useful sometimes.