On Windows Command Line I would like to loop over a list the following way:
list = 1,2,4,8,4,1,5
for /f %x in list do (echo %x)
But the above does not work, so how one loop over a list with the Windows Command line?
On Windows Command Line I would like to loop over a list the following way:
list = 1,2,4,8,4,1,5
for /f %x in list do (echo %x)
But the above does not work, so how one loop over a list with the Windows Command line?
Save this as a batch file and run it from Command Prompt.
@echo off
set mylist=does,this,work
for %%i in (%mylist%) do (
echo %%i
)
The FOR
command is mostly used to process files, but you can also process a text string:
FOR %X IN ("1" "2" "3") DO Echo %X
PowerShell:
1,2,4,8,4,1,5 | ForEach-Object { $_ }
PowerShell has built-in support for lists and has a far more consistent syntax than cmd.exe. I would recommend giving it a try.