Batch Scripting

Miscellaneous tips to build useful one-liners or bash scripts.

Table of Contents



File Descriptors

Name Description
nul Equivalent to /dev/null
1 (or nothing) Standard Output
2 Standard Error

FOR loops

Loop over a simple counter:

for /L %i in ([start],[step],[stop]) do [command]

Infinite loop:

for /L %i in (1,0,2) do [command]

Loop over lines of a file:

for /F %i in ([filename]) do [command]

Loop over the output of a command:

for /F %i in ('[command]') do [command]

Loop over a string:

for /F %i in ("[string]") do [command]

Pause Execution

timeout /t [seconds] /nobreak

Run Multiple Commands

Use & and && to run multiple commands on a single line: