I'm trying to set the variable of of the for statement to another variable. When I'm doing this:
for /f "tokens=* delims= " %%p in (plugins.txt) do set pp = %%p
It works correct. But I want to do more, So I do it after the ( and now it doesn't work. Why is that and how can I solve it?
for /f "tokens=* delims= " %%p in (plugins.txt) do (
set pp = %%p
echo %pp%
echo %pp%
echo %%p)
EDIT: Added input and desired output
content of plugins.txt
http://subversion/svn/dotCMSPlugins/CustomLogin/trunk
Desired output
CustomLogin
The setting works, but the expansion works in an other way as expected.
The percent expansion will be done in the moment of parsing the parenthesis block, not in the moment of execution of the single commands. How does cmd.exe parse scripts
Btw. Using spaces in the set statement isn't a good idea, as it creates a variable with a space, in your case
set pp = %%p
creates a variable namedpp<space>
with a value of<space><content of %%p
.You can get the desired results by using delayed expansion.
If your input file contain this line:
and you want to get this result:
then the easiest way is to separate the line in tokens by / character and take the 4th token this way:
If the purpose of the FOR is just to get this result, then the delayed expansion is not even necessary: