Search code examples
shellpowershelldos

Can command aliases be added to a DOS shell automatically?


Is there a way to make all DOS shells on my Windows 7 system have this command alias?

doskey h=doskey /history

Is this possible, in the same way that a Bash shell can load a .bash_profile ? I am looking for an answer that does not require PowerShell.


Solution

  • Well DOS isn't really the right word here. In current versions of Windows, you have the CMD.exe shell that has many of the same commands as DOS (dir, copy, etc). You may also have PowerShell. In PowerShell it is easy to configure an alias to always be available. Create a file called $home\Documents\WindowsPowerShell\profile.ps1 and create your alias like so:

    New-Alias h Get-History # Don't execute as it already exists
    

    However, PowerShell has already created this particular alias for you. Just open PowerShell, execute a few commands and then execute h.

    As for CMD.exe this blog post describes how to configure CMD.exe to do the same.