Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setx setting PATH with spaces

I am trying to update the system Path variable in a win32 shell script but only if a value is not present.

My current version looks something like this:

for %%f in (xyz.exe) DO if [%%~$PATH:f]==[]; setx Path "%PATH%;%GRADLE_HOME%\bin" -m

The problem I am having is with

setx Path "%PATH%;%GRADLE_HOME%\bin"  

This doesn't work, but if I change the quotes to single quote

setx Path '%PATH%;%GRADLE_HOME%\bin'

It does work but the Path ends at the first occurrence of Program Files. I.e abc;def;Program

Is there any way to overcome this?

like image 728
Shawn Vader Avatar asked Dec 13 '22 01:12

Shawn Vader


1 Answers

Actually there is an easier way.. it seems to work but it is somewhat ugly and non-intuitive:

setx /M Path "%PATH%;%GRADLE_HOME%\bin

Notice that there is ONLY one double-quote and it is at the beginning .. if you put one at the end, it ends up in the path string (without the one at the beginning).

like image 166
Eric Avatar answered Dec 24 '22 16:12

Eric