Score:0

Modify path to include quotes

cn flag

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?

vanadium avatar
cn flag
Some "hygiene" in your PATH may be warranted: you cannot have a path for every executable everywhere in your system. Instead learn to work with symlinks or wrapper scripts placed in a directory in your existing path. An overly long path is difficult to maintain and may at some point slow down launching applications.
Sunshine avatar
cn flag
Thanks vanadium. I appreciate the feedback.
Score:1
cn flag

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.

Sunshine avatar
cn flag
Thanks. This worked. Now I have to figure out why the script is still resulting in an error after adding the quotes to account for the spaces in the directories.
Score:1
uz flag
Jos

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.

Sunshine avatar
cn flag
Thanks for the feedback. Am I missing a step? I tried the command after double-checking it but I still have the same issue. None of the paths with spaces are surrounded in quotes if I do printenv after issuing the command. I also tried escaping the spaces with the \ character. Neither updated path. I also opened a new terminal window after these changes. So far, I haven't found how to apply the changes and they remain in the system.
vanadium avatar
cn flag
It is normal that the quotes or escape signs are not visible in the PATH variable itself. I now realize that we are all misunderstanding your question. Use escape sign or single quotes to insert the quotes in the variable itself, but make sure you know why you want this.
Sunshine avatar
cn flag
I'm not sure what I'm doing wrong. I've tried using single and double quotes, along with the escape character, a few times now. I'm working with some scripts in ubuntu from the Kaldi tool that use PATH and because of the spaces in PATH, I get errors.
Sunshine avatar
cn flag
I was missing the single quotes. Thanks. That did update the path. Unfortunately, I'm still getting the errors.
Sunshine avatar
cn flag
I'm working with Kaldi scripts on Ubuntu in WSL. Is anyone able to share why after I rebooted my machine or open a new Ubuntu terminal, the PATHs I updated to account for spacing in the directories has now reverted back to no double quotes? I've tried using the \ to escape the spacing. I still get the same error as if spacing is still included in the paths in that terminal. I've added echo statements to show that the PATHs have the double quotes for spacing but the same error happens as if the spacing is still there in the current terminal where the updates have been made.
Sunshine avatar
cn flag
Is there any way to make the updates permanent or is that frowned upon?
uz flag
Jos
I would delete my answer, were it not for the valuable comments that followed.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.