I’m trying to make a code which will get first words from all lines of HELP’s output to a variable and echo this variable. Here is my code:
@echo off
set a=
for /F "tokens=1,*" %%i in ('help') do (
set a=%a% %%i
)
echo %a%
But it returns first word from only last line. Why?
You need to use delayed expansion in your
forloopInstead of using
%‘s around theavariable, you use!‘s to use delayed expansion.