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.

Similar Reads

What is an Alias?

Alias is a shorthand command to replace another command. We can think of it as a shortcut command for multiple or long commands. It can be also understood as a map of the shortcut keyword command with the actual command. The shortcut command is replaced with the string of commands which gets executed....

Creating an Alias

To create an alias in a windows environment or a BATCH script, we can open up a CMD or Powershell instance....

Creating a permanent alias

To create a permanent alias, we can specify these same commands of doskey in a .bat file which is also known as the Batch script or file. After the batch script/file is created with the alias you required we can copy the path of this batch file and add it to the CMD/Powershell target to add the alias in the initialization of those environmental shells(CMD/Powershell)...

Replacing an Alias

To replace an alias in a batch environment, we can simply edit the shortcut name to the command we want to replace with....

Deleting an Alias

To disable or delete an alias is quite straightforward. We can set the shortcut alias command to empty and the Shell environment will not consider it as a valid command anymore....

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....

Contact Us