In a command prompt, you can use DOSKEY for creating macros. In a batch file you can define a variable that can be called as a piece of code and even pass arguments to it.
DOSKEY, we can create macros to simplify typing many commands in command prompt. Take a look at the following example.
DOSKEY macro=echo Hello World
Now if you type
macro in the command prompt, it would return
DOSKEY macro doesn't support comment, but there's a workaround.
;= Comment ;= Comment ;= Remember to end your comment with ;= ;=
There are 3 usages of the
$ character in a
$T is the equivalent of
& in a batch script. One can join commands together like so.
DOSKEY test=echo hello $T echo world
batch), we use
$ to indicate command-line argument.
$1 refers to the first command-line argument
$2 refers to second command-line argument, etc..
$* refers to all command-line argument
DOSKEY macros don't work in a batch script. However, we can use a little workaround.
set DOSKEYMacro=echo Hello World %DOSKEYMacro%
This script can simulate the macro function. One can also use ampersands(
&) to join commands, like