3
2
While at work, I want to use the CLI to be more productive on my Windows machine. What command, in Windows, would be a replacement for the alias
command?
3
2
While at work, I want to use the CLI to be more productive on my Windows machine. What command, in Windows, would be a replacement for the alias
command?
6
doskey com=a long command $*
Here $*
expands to everything typed after com
. For example, com Hi!
would be expanded to a long command Hi!
cmd.exe
shell – it works with any program that uses a Win32 console window. (For example, for Python's interactive shell, use doskey /exefile:python.exe ...
)See doskey /?
for usage. The aliases can also be added programatically; see Console Aliases for the API.
To apply aliases automatically whenever cmd.exe
is launched:
Put them in a text file, in the form alias=expansion
:
com=very long example command
cd=cd /d $*
I keep my aliases in %AppData%\doskey.txt
.
Create a batch script containing the doskey
command:
@echo off
doskey /macrofile:"%AppData%\doskey.txt"
Of course, point /macrofile
to the location you have chosen in step 1.
A good name for this script is %AppData%\autorun.cmd
.
In Registry, open key HKEY_CURRENT_USER\Software\Microsoft\Command Processor
and point the value AutoRun
to the script.
regedit
, navigate to the given key.AutoRun
does not exist, create it: right-click → New → String0
I assume you mean the "alias" command. Dos/NT command prompts support "alias" as a command with the following syntax:
alias
See the wikipedia article for details: http://en.wikipedia.org/wiki/Alias_(command)
Doesn't look like it, I just tried it. Win XP. But that wikipedia article does mention powershell and 4DOS and 4NT having a command for aliases but maybe not that syntax. – barlop – 2011-04-11T20:05:23.803
What about using Set?
I just tested in XP, set ckh = "George" and it set an environment variable ckd as "George". Is this an analog to alias? – music2myear – 2011-04-11T20:25:41.213
@music2myyear No. An alias is like a substitution. So typing C:>doskey tt=blah <ENTER> that sets up an alias tt=blah, means when you type tt and press ENTER, then it acts like you typed blah and pressed enter. So it's like a shortcut. With set, if you do set ckh=George Then ckh ENTER will still be ckh ENTER. But %ckh% will use the contents of the ckh environemnt variable i.e. George. The %s are not so convenient as with an alias, – barlop – 2011-04-11T23:31:06.333
@music2myyear but it's a very different concept really. A variable is like a container with a name and a value and is meant to change at times you want. An alias is like a shorthand way of saying something, it's more static.. if you kept changing your aliases you'd get confused.. 'cos they're meant to be easily memorable shorthands for specific commands with certain options you don't want to have to retype. – barlop – 2011-04-11T23:33:34.773
Got it and thank you for the explanation. I've never much gotten into programming or scripting or admin-ing on *nix systems and so was (obviously) not familiar with the concept. But now I'm a little more so thanks to y'all. – music2myear – 2011-04-12T02:45:53.593
You can simply save the current configuration:
doskey /macros:all > "%AppData%\doskey.txt"
. This file has sections per EXE name, such as[cmd.exe]
. – Eryk Sun – 2014-12-23T00:32:22.270I attempted this method on windows 7, but had no luck. when I attempt to directly execute the
autorun.cmd
, I get anInvalid macro definition
error (I turned@echo on
to see the output). are there any suggestions for what might cause this? – ewok – 2012-05-15T15:22:10.5301nevermind. Just to let you know, there is an error in your answer. the autorun.cmd file needs to say
doskey /macrofile=...
. note the=
instead of the:
– ewok – 2012-05-15T15:26:01.633