Tuesday, 15 April 2014

for loop - Batch File Setting an Environment Variable -



for loop - Batch File Setting an Environment Variable -

i have code in batch file store value in variable %%i:

for /f %%i in (aylaunits.txt) set %%i set "$unit=%%i" echo unit : %$unit% pause

this seems loop fine, each item response:

set ac000w000004591 environment variable ac000w000004595 not defined unit : %i

there going 100+ different lines in text file. need create environmental variables each one? don't think that's best way , i'm not sure i'm understanding environmental variables correctly.

i need plug each line of file url section if that's of importance.

thanks, dm

you have syntax issue, see proposed alter below:

setlocal enabledelayedexpansion /f %%i in (aylaunits.txt) ( set "$unit=%%i" echo unit : !$unit! ) pause

please see edit above, since we're setting variable within for loop, need utilize setlocal enabledelayedexpansion able expand on it. since we're expanding var that's set in for loop, need utilize ! instead of % when using variables.

batch-file for-loop

No comments:

Post a Comment