batch files

References

Summary

.bat and .cmd files are more or less the same thing nowadays

echo

Use the @ symbol to prevent a line from writing to standard output

echo off turns off the printout for every subsequent command

Scope

SETLOCAL is a scope boundary

Execution

By default all loops parse at once at load time

EnableDelayedExpansion: Allows us to read variables dynamically as they update

Sanitization

Variables

Define variables with SET But be careful about quotes

Loops

FOR /L %%i IN (0,1,2) DO (
SET "REPO=!REPOS[%%i]!"
...
)

The exclamation points say that the variable is updating throughout the loop. /L is a flag that says we're using an explicit numeric counter (0,1,2) denotes

Commands

%1 represents the first command-line argument passed to the batch script

%~1 strips any quotation marks placed around the command by the VBS caller

Errors

if errorlevel X: checks if the preceding command's return code is ≥ X