SET CLIENTS=blah1:blah2
for %%x in (%CLIENTS::= %) do (
SET client=%%x
echo %client%;
if "%1"==%client% goto end
)
:end
I would expect to compare blah1 and %1 first and blah2 and %2 second.
However, the %client% will only be assigned with blah2. Any ideas how to resolve this issue?
The expansion of variables inside
FORloops requires you to enable delayed expansion to force variables to be expanded at runtime instead of being expanded when parsed. ReadHELP SETfor more information.And try changing your code to
Note that the variable is referenced with an slightly different syntax
!client!instead of%client%. Delayed environment variable expansion allows you to use a different character (the exclamation mark) to expand environment variables at execution time.