0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Working smoothly. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.