0

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?

2
  • 1
    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.
    – vanadium
    Commented Oct 12, 2021 at 14:27
  • Thanks vanadium. I appreciate the feedback.
    – Sunshine
    Commented Oct 12, 2021 at 19:13

2 Answers 2

1

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.

7
  • 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.
    – Sunshine
    Commented Oct 12, 2021 at 19:11
  • 1
    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.
    – vanadium
    Commented Oct 12, 2021 at 19:19
  • 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
    Commented Oct 12, 2021 at 20:24
  • I was missing the single quotes. Thanks. That did update the path. Unfortunately, I'm still getting the errors.
    – Sunshine
    Commented Oct 12, 2021 at 20:48
  • 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
    Commented Oct 13, 2021 at 15:19
1

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.

1
  • 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.
    – Sunshine
    Commented Oct 12, 2021 at 20:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .