Monday, November 20, 2006 6:30 AM bart

Quiz: Batch scripting mysteries

Can you predict what the following piece of batch script will produce (and why)? Tip: run it more than one time.

@echo off for %%f in (a,b,c) do ( echo 1 %%f 2 set x=x1 %%f x2 echo %x% )

Source: question at the TechEd 2006 IT Forum ATE.

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Comments

# re: Quiz: Batch scripting mysteries

Monday, November 20, 2006 9:33 AM by Eber Irigoyen

something with the scope... I think Raymond talked about this once

# re: Quiz: Batch scripting mysteries

Wednesday, November 22, 2006 9:26 AM by denis bider

The %x% is evaluated when the body of the for loop is read, not when it is executed. So it most likely prints something like "x1 a x2" 3 times the first time it's run, and "x1 c x2" on the second and subsequent runs.

# Answers to quiz - Batch Scripting Mysteries

Monday, November 27, 2006 2:43 PM by B# .NET Blog

A few days ago, I posted this little quiz on batch scripting mysteries . The batch script given was: