Reputation: 8850
I need to eval the commands thrown by some command 'minishift oc-env' which has PATH in it.
However, it seems that it is overwriting the whole PATH variable.
C:\Users\budhram>echo %PATH%
C:\Program Files\Docker\Docker\Resources\bin;C:\Users\budhram\AppData\Local\Temp;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;.....
C:\Users\budhram>minishift oc-env
SET PATH=C:\Users\budhram\.minishift\cache\oc\v1.5.0;%PATH%;
REM Run this command to configure your shell:
REM @FOR /f "tokens=*" %i IN ('minishift oc-env') DO @%i
C:\Users\budhram>SET PATH=C:\Users\budhram\.minishift\cache\oc\v1.5.0;%PATH%;
C:\Users\budhram>echo %PATH%
C:\Users\budhram\.minishift\cache\oc\v1.5.0;C:\Program Files\Docker\Docker\Resources\bin;C:\Users\budhram\AppData\Local\Temp;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;....
C:\Users\budhram>@FOR /f "tokens=*" %i IN ('minishift oc-env') DO @%i
C:\Users\budhram>echo %PATH%
C:\Users\budhram\.minishift\cache\oc\v1.5.0;%PATH%;
Any idea how we can do that?
This answer https://stackoverflow.com/a/9370376/1120530 also suggest about using setlocal enableDelayedExpansion
which seems to be not working in my case.
Upvotes: 0
Views: 836
Reputation: 70943
When you run
@FOR /f "tokens=*" %i IN ('minishift oc-env') DO @%i
the do
clause will execute
SET PATH=C:\Users\budhram\.minishift\cache\oc\v1.5.0;%PATH%;
which seems correct, BUT the problem is that after %i
has been expanded to the indicated command, there is not a second expansion to convert %PATH%
to the value in the variable.
You can try with
@FOR /f "tokens=*" %i IN ('minishift oc-env') DO @call %i
where the call
command will force a second parse phase that will expand the %PATH%
reference.
Upvotes: 1