Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file - loop to append strings to variable

Tags:

batch-file

How come this keep replacing the variable with each data from the loop instead of appending it?

set ipList=
for /F %%i in (ips.txt) do ( set ipList=%ipLis%,%%i )
like image 608
jt123 Avatar asked Jan 09 '23 22:01

jt123


1 Answers

It's true you need delayed expansion. Another way:

setlocal ENABLEDELAYEDEXPANSION
set ipList=
for /F %%i in (ips.txt) do ( set ipList=!ipList!,%%i )

Note the '!' instead of '%%'. Also, there was a typo in your question, I suppose it should be %%ipList%% instead of %%ipLis%% (a 't' is lacking).

like image 165
Migtor Avatar answered Jan 15 '23 23:01

Migtor