Options/Parameters in Batch Aliases
We can use certain parameters and options in the alias to integrate certain features that can be more used to make the alias more flexible.
There are several parameters as follows:
parameter/option | description |
---|---|
/history | to get the history of the current batch environment (commands executed in CMD/ Powershell) |
/exename | to execute the macro with an executable in the system path |
/macrofile | to include a file that contains the macro to be used |
There are a lot of options and parameters we can use to enhance the alias in our batch script
Note: The entire list of options/parameters can be found in the official Microsoft docs.
We can even use command line arguments in the alias as we do with the normal batch script. This can be a really powerful tool to have especially for more complex batch tasks and scripts. Let’s say we want to create an alias that creates a folder and changes our current directory into the created folder. We can use the positional parameter specified as the folder name and create and cd into the folder.
doskey md = mkdir $1 &t cd $1
We can use the $1 to indicate the first parameter passed to the alias and $t to separate the commands in the alias.
Thus, we can now dynamically use our alias in a batch script or CMD/Powershell environment. This can be further used as per the specification of the commands.
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.
Contact Us