I\'ve been programming in dozens of languages for 20 years but I could never understand how \"FOR\" work in windows cmd shell batch file, no matter how hard I tried. I read
for /f iterates per line input, so in your program will only output first path.
for /f
your program treats %PATH% as one-line input, and deliminate by ;, put first result to %%g, then output %%g (first deliminated path).
;