Batch programming has been greatly enhanced in modern operating system e.g. XP or afterwards. It is in fact possible to write complex and useful applications using Windows batch programming. In [here], a basic example is given using Linux BASH shell, which prints a chess board with 8 X 8 squares, black and white interleaving. Here is the equivalent script in windows batch.
The above script will give the following output.
Here are some quick explanations for the commands used in the script. The title will set the title of the command window. The mode can be used to change the number of columns or rows (lines). The cls clears the screen. The setlocal begins a local block that all the variables set remain local until endlocal or the current script exits. setlocal can take two parameters, enableextensions enables command extensions. The opposite is disableextensions. The enabledelayexpansion allows variable substitution at runtime instead of parsing time. If this is not set, the variables wrapped with %var% will be substitute at parsing time. The enabledelayexpansion will expand each variable wrapped with !var! at execution time. The block statements are enclosed by brackets, meaning the commands are grouped as a single one. It is noted that in command line, the variable representation by command for is a sinlge % while in the script, it should be replaced by a double %. The special characters should be taken care, for example, ^) prints ) and %% prints a single %. The black square is printed using ASCII code 219. The exit command takes the parameter /b that means exiting the current script. Please note that there is a space after the end of the set statement in the else block. This prints the empty space (white square). A double : begins a comment that is the same thing as rem. The set /a begins the arithmetic expression.
–EOF (The Ultimate Computing & Technology Blog) —
a WordPress rating system
Last Post: Self-executing Anonymous Functions in Javascript
Next Post: Get String Length using Windows Batch