Link to home
Start Free TrialLog in
Avatar of detox1978
detox1978Flag for United Kingdom of Great Britain and Northern Ireland

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
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of detox1978

ASKER

great that worked a treat.


What does the second % do?
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
cheers.


that was the problem, i tested it from the command line.....


thanks again.