How to assign %%parameter to variable?
FOR /F "tokens=1 delims= " %%A IN (connections.txt) DO (
set USER=%%A
echo A=%%A
echo USER=%USER%
)
Output of this code:
A=user1
USER=
How to assign parameter %%A to variable USER?
How to assign %%parameter to variable?
FOR /F "tokens=1 delims= " %%A IN (connections.txt) DO (
set USER=%%A
echo A=%%A
echo USER=%USER%
)
Output of this code:
A=user1
USER=
How to assign parameter %%A to variable USER?
The parameter %%A was correctly assigned to USER variable, but USER value is not correctly shown.
To use the current value of a variable that was modified inside a FOR loop, you must use Delayed Variable Expansion, that is, change the percent by exclamation mark this way:
FOR /F "tokens=1 delims= " %%A IN (connections.txt) DO (
set USER=%%A
echo A=%%A
echo USER=!USER!
)
and include this line at beginning:
setlocal EnableDelayedExpansion
Otherwise, the value of %USER% is the one the variable had before entering the FOR loop.