Creating an Alias
To create an alias in a windows environment or a BATCH script, we can open up a CMD or Powershell instance.
The structure of an alias is as follows:
doskey parameters [shortcut command] = [commands to be executed]
A simple alias in BATCH scripting will look something like the following:
doskey cdoc = cd C:\Users\Admin\Documents
We use the keyword doskey to create an alias, the alias is simply created by specifying the shorthand command in this example the word cdoc and the final piece of information is the actual command we want to replace with this alias. Thus when we create this alias, the command cdoc executes the command cd C:\Users\Admin\Documents and hence we optimize and create a shortcut to save some time and effort.
This will create an alias for this CMD/Powershell instance only, once you exit the session or window the alias is no longer working and hence was a temporary alias.
Batch Script – Aliases
Be it Linux, macOS, or Windows, we sometimes need to use the terminal or the command line to perform certain commands. If in such situations, we find ourselves repeating a few long commands we can use an alias to save time and make it easier. In windows, we can create an alias as a batch command from the command prompt or the Powershell. We will see how to create and work with an alias in Batch scripting.