16 CODE BLOCKS

A code block can sometimes be a rather generic term, referring to some amorphous section of a program or a few lines of code. In Batch, it’s a well-defined entity: one or more commands in between a set of open and close parentheses. A prominent example is the code often executed when an if command is true.

That seems simple enough, but it’s far more difficult to use a code block properly and wisely than it is to define it. A very powerful feature of Batch is that delayed expansion allows you to resolve variables in two distinct ways inside a code block, but the uninitiated often misinterpret that functionality as a bug. In ...

Get The Book of Batch Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.