How do SETLOCAL and ENABLEDELAYEDEXPANSION work?

I think you should understand what delayed expansion is. The existing answers don’t explain it (sufficiently) IMHO. Typing SET /? explains the thing reasonably well: Delayed environment variable expansion is useful for getting around the limitations of the current expansion which happens when a line of text is read, not when it is executed. The … Read more

How does the Windows Command Interpreter (CMD.EXE) parse scripts?

We performed experiments to investigate the grammar of batch scripts. We also investigated differences between batch and command line mode. Batch Line Parser: Here is a brief overview of phases in the batch file line parser: Phase 0) Read Line: Phase 1) Percent Expansion: Phase 2) Process special characters, tokenize, and build a cached command … Read more

When do we need curly braces around shell variables?

In this particular example, it makes no difference. However, the {} in ${} are useful if you want to expand the variable foo in the string “${foo}bar” since “$foobar” would instead expand the variable identified by foobar. Curly braces are also unconditionally required when: expanding array elements, as in ${array[42]} using parameter expansion operations, as … Read more