63 lines
1.9 KiB
Text
63 lines
1.9 KiB
Text
= Windows cmd shell batch scripting cheat sheet
|
|
Yuri Slobodyanyuk <admin@yurisk.info>
|
|
v1.0, 2022-08-31
|
|
:homepage: https://yurisk.info
|
|
:toc:
|
|
Author: Yuri Slobodyanyuk, https://www.linkedin.com/in/yurislobodyanyuk/
|
|
|
|
|
|
== Controlling scripts themselves
|
|
[cols=2, options="header"]
|
|
|===
|
|
|Command
|
|
|Description
|
|
|
|
|*rem*
|
|
|Start a comment, till the end of line. It can be used to comment out a whole line or part of it.
|
|
|
|
|*cls*
|
|
|Clear the screen buffer.
|
|
|
|
|*echo _text to display_*
|
|
|
|
*echo off/on*
|
|
|
|
*echo.*
|
|
|Print text on line, or, with `off/on` switch without text, turn off/on echoing the commands being run.
|
|
Usually, you set `echo off` as the 1st line in a batch script, and the `echo on` as the last line. Turning
|
|
echoing off does not hide _output_ of the commands run, just the commands themselves. The 3rd option is `echo` followed immediately
|
|
by _dot_ and it causes echo to print a blank line (an dthis is the only way to do so).
|
|
|
|
|*@*
|
|
|Turn off echoing only for the command preceded by this @. E.g. `@echo off` to prevent the _echo off_
|
|
being printed itself.
|
|
|
|
|*title _Title bar text_*
|
|
|Change the title of the cmd.exe window for this session. As a rule of a good style, change _title_ on each stage of the
|
|
script, to let users know what the script is doing.
|
|
|
|
|
|
|===
|
|
|
|
|
|
== Script arguments
|
|
[cols=2, options="header"]
|
|
|===
|
|
|Command
|
|
|Description
|
|
|
|
|%_n_
|
|
|Positional argument to the script from the command line. _n_ can be from 0 to 9.
|
|
|
|
|%0
|
|
|The script name. The actual arguments to the script start with %1.
|
|
E.g. `echo The script was called as %0, with the %1 as the first argument`
|
|
|
|
|%*
|
|
|The rest of the positional arguments after the 9th altogether. The individual args are not accessible directly, use `SHIFT`-ing.
|
|
|
|
|*shift [/_n_]*
|
|
|Shift positional arguments by one. If `/n` is given, will shift starting with n+1. E.g. `shift /4` will shift 5th to become 4th,
|
|
6th will become 5th, and so on, while arguments before 4 will stay untouched.
|
|
|
|
|===
|