WSL: Spaces in windows path breaks in Bash
Brief description
Using windows tools from Bash fails when using a path that has a space.
The windows path is added to the $PATH and some translation happens ie C: => /mnt/c. Spaces are not managed in this translation. This means any windows path that includes a space (Program Files or user paths with a space as below) fail to find files.
Expected results
Files found and are accessible.
Actual results
username@DESKTOP-M7UD40T:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/System32:/mnt/c/Windows:/mnt/c/Windows/System32/wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Program Files/nodejs:/mnt/c/Program Files/Microsoft SQL Server/130/Tools/Binn:/mnt/c/Program Files/dotnet:/mnt/c/Program Files/Git/cmd:/mnt/c/Users/User Name/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/User Name/AppData/Local/atom/bin:/mnt/c/Users/User Name/AppData/Roaming/npm
username@DESKTOP-M7UD40T:~$ apm
/mnt/c/Users/User Name/AppData/Local/atom/bin/../app-1.14.4/resources/cli/../app/apm/bin/apm: line 37: /mnt/c/Users/User Name/AppData/Local/atom/app-1.14.4/resources/app/apm/bin/node: No such file or directory
username@DESKTOP-M7UD40T:~$ ls /mnt/c/Users/User Name/AppData/Local/atom/app-1.14.4/resources/app/apm/bin
ls: cannot access 'Name/AppData/Local/atom/app-1.14.4/resources/app/apm/bin': No such file or directory
/mnt/c/Users/User
username@DESKTOP-M7UD40T:~$ ls "/mnt/c/Users/User Name/AppData/Local/atom/app-1.14.4/resources/app/apm/bin"
apm apm.cmd etc node.exe npm npm.cmd python-interceptor.sh
username@DESKTOP-M7UD40T:~$
Windows build number
Microsoft Windows [Version 10.0.15042]
Repro Steps
Install Atom Editor & node.js in windows land
open bash shell
run apm command
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 7
- Comments: 33 (5 by maintainers)
I fixed the error, by not adding the Windows Path entries to the Linux Path. Open a wsl terminal, create or edit the
wsl.conffile under/etcwith the following commandAdd the following content:
Save the file and restart the wsl. I used the following command to shutdown the wsl (closing the terminal window and open it again didn’t work)
Start a new wsl termial and check if the Windows Path entries are gone
Output should look like
I don’t know why anyone here faults this to the user. In Windows paths don’t need to be escaped, that’s why no program out there escapes their path they add.
xxx@PC:~$ $PATH -bash: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Python38/Scripts/:/mnt/c/Python38/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program: No such file or directoryNotice how everything after “Program Files” is cut off?
How is it not WSL’s bug when it automatically adds Windows paths which work on Windows like they are, to the bash in a way that breaks them?
What is the user supposed to do, modify all their Windows paths? And do it again any time some program adds their path?
@emrsmsrli this isn’t all that useful when it’s the automatically generated path (Ubuntu + Windows) that has the spaces. I don’t plan on typing /mnt/c/some\ long\ path\app.exe every time I want to run something that’s already in the path.
My envisioned fix is that the auto combine process is updated to escape spaces exactly like that though. It’s not just “User Name” paths that will see this issue but also anything in Program Files.
you can use escape character
\before a space character as in"C:\Users\Emre\ Simsirli".Hi, The solution to this is to double-quote the string eg:
Found here: https://stackoverflow.com/questions/40135502/opening-sublime-text-from-bash-on-ubuntu-on-windows
I’m quite familiar with quoting and escape characters in nix. It simply does not work when passing the $BROWSER variable from bash to sensible-browser. In .bashrc, I tried single quote, double quotes, escape characters and even double quote embedded in single quote:
export BROWSER="/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'export BROWSER='"/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"'export BROWSER="/mnt/c/Program\ Files\ (x86)/Google/Chrome/Application/chrome.exe"All produce the error:
$ source ~/.bashrc$ /usr/bin/sensible-browser/usr/bin/sensible-browser: 6: /usr/bin/sensible-browser: /mnt/c/Program: not foundThe only fix so far: In file
/usr/bin/sensible-browser, update line that reads${BROWSER} "$1"to"${BROWSER}" "$1"Good point re bug in sensible-browser. Will report there.
This is definitely a bug and should be fixed. To fix manually:
In file
/usr/bin/sensible-browser, update line that reads${BROWSER} "$1"to"${BROWSER}" "$1"Hey, there. I stucked with same problem.
Path just breaks on first space. Any ideas?
Hi @themaninthesuitcase – just for completeness, could you try running
apm.exe(including the.exe)? WSL requires the file extension.