detox1978
asked on
Nested 'For' issue in a Batch Script
Hi all, any idea why this nested FOR statement isn't working?
@echo off
for /f %%a in ('type users.txt') do (
echo Processing %%~a
FOR /F "Tokens=3 Delims=," %s IN ('dsquery user -samid %%~a') DO @ECHO %s
)
echo Done.
pause
@echo off
for /f %%a in ('type users.txt') do (
echo Processing %%~a
FOR /F "Tokens=3 Delims=," %s IN ('dsquery user -samid %%~a') DO @ECHO %s
)
echo Done.
pause
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thats great!
Actually if you run FOR loop from command line (not from the batch) then you will use single % sign and if you use it from batch file then you will have to %% for a variable name.
LIKE:
Click Start -> Run -> Cmd.exe -> OK
FOR /F %a IN ('TYPE users.txt') DO @ECHO %a
Above statement will work perfectly from command problem but will not work in batch file, you have to give two two percent sign (%%).
:: Abc.cmd contents
FOR /F %%a IN ('TYPE users.txt') DO @ECHO %%a
For more info:
Click Start -> Run -> Cmd.exe -> OK
FOR /?
Hope this helps!
Farhan
Actually if you run FOR loop from command line (not from the batch) then you will use single % sign and if you use it from batch file then you will have to %% for a variable name.
LIKE:
Click Start -> Run -> Cmd.exe -> OK
FOR /F %a IN ('TYPE users.txt') DO @ECHO %a
Above statement will work perfectly from command problem but will not work in batch file, you have to give two two percent sign (%%).
:: Abc.cmd contents
FOR /F %%a IN ('TYPE users.txt') DO @ECHO %%a
For more info:
Click Start -> Run -> Cmd.exe -> OK
FOR /?
Hope this helps!
Farhan
ASKER
cheers.
that was the problem, i tested it from the command line.....
thanks again.
that was the problem, i tested it from the command line.....
thanks again.
ASKER
What does the second % do?