Modify path to include quotes

Ubuntu is installed on a Windows OS. I have searched and found how to add a new path but I'm not quite getting how to modify a path that already exists and then adding quotes around paths with spaces. I have the following in path:

PATH=/usr/local/cuda-11.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/Common Files/Oracle/Java/javapath:/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 Files/Git/cmd:/mnt/c/Python27:/mnt/c/Python27/Scripts:/mnt/c/Program Files/PuTTY:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/amason1/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin

How do I modify path in order to put quotes around Program Files in /mnt/c/Program Files/Git/cmd?


This should work:

PATH=/usr/local/cuda-11.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:"/mnt/c/Program Files/Common Files/Oracle/Java/javapath":/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 Files/Git/cmd":/mnt/c/Python27:/mnt/c/Python27/Scripts:"/mnt/c/Program Files/PuTTY":"/mnt/c/Program Files/Docker/Docker/resources/bin":/mnt/c/ProgramData/DockerDesktop/version-bin:"/mnt/c/Users/amason1/AppData/Local/Programs/Microsoft VS Code/bin":/snap/bin

Basically, you place double quotes (") around directory names that contain spaces, like e.g.:

/mnt/c/Program Files/Common Files/Oracle/Java/javapath

so they become

"/mnt/c/Program Files/Common Files/Oracle/Java/javapath" 

Alternatively, escape the spaces with the \ character, as in:

/mnt/c/Program\ Files/Common\ Files/Oracle/Java/javapath 

Please, double check the above command before issuing it, or you may run into problems.


To insert literal double quotes in the PATH variable, you either surround the pathname with ' or escape the special characters preceding them by \. Thus, either of the following will work:

PATH=...:'"/mnt/c/Program Files/Git/cmd"':...

or

PATH=...:\"/mnt/c/Program\ Files/Git/cmd\":...

You may have your own good reasons for wanting to do this. Just know that folder "/mnt/c/Program Files/Git/cmd" is different from folder /mnt/c/Program Files/Git/cmd. The former is not an absolute path, so will be found only if it exists in the current directory.