Alias is a term borrowed from Unix.
A Unix alias is a symbol maintained by the command shell that acts as a shortcut. Each alias has a string value which is substituted for the for it when the alias is typed.
In other words, if Windows supported alias, one could set up an alias msword whose string value is "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE".
Now if one typed msword on the command line, Microsoft Word would be started.
When working from a command prompt I would find this tremendously useful. I wouldn't have to pop back to the start menu or an explorer window to start up another program.
But windows does not have aliases per se. It does have some mechanisms that sort of do the same thing but they all present problems for me as decribed here.
So I wrote a program, mkalias.c which generates something that works more like a Unix alias. What it actually does is generate a program which contains a fixed string. When the alias program name is typed any arguments on the command line are placed at the end of the fixed string and the resulting command is run as if it were typed in the first place.
This might be clearer with an example:
I have an alias on my system:
msword is an alias for "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"
If I type msword, Microsoft word starts up. If I typed msword resume.doc, Word starts up to edited the resume.
The mkalias program is evolving. Right now it is a little tricky (or clever, depending on your persuasion).
Currently mkalias generates a C program containing the fixed string mentioned above and (optionally) compiles that program to generate the actual alias program.
This means that you have to have a C compiler on your system (currently Microsoft C and gcc are supported if mkalias.exe compiles the generated program itself.
I expect that this is a little confusing. The basic reason I wrote it was that I wanted a way to invoke a Windows program from the command line and each of the standard ways I knew how to do it had problems as described here.
As with most of the stuff on this web site, it is assumed that mkalias.exe is somewhere on your command PATH and that the generated alias program will be also, probably in the same place.
- Removing the need for a C compiler
I think it is a drawback that you need a C compiler to generate an alias program. As I wrote this article it occurred me that this was not necessary. I could use the current version of mkalias to generate a generic alias program. I could then compile the generic version and include it as data in a new version of the mkalias program itself.
When this new version of mkalias is run it will modify its internal version of the generic program with the string data the user specified and write it out as a new executable program - no compiler needed. I'll probably use Microsoft C version 6 to compile; it seems to work out-of-the-box on most of the versions of Windows I've seen.
- If you want to use mkalias now you'll have to compile it. When you run it you have to specify several parameters: the name of the alias, the equivalent string, and a bunch of options. Even though I wrote it, I never remember the usage syntax so I wrote a command procedure, xmkalias, to help. Perhaps I'll incorporate xmkalias with the next version of mkalias so that, if not specified on the build command line, it will prompt for the information it needs.
- The command being aliased does not have to be on the PATH (which is one of the reasons I wrote this in the first place).
- mkalias adds to "options" to the alias command it generates
- --alias will display the alias name and what command string it is aliased to
- --mkalias will display the command string used to create the alias (useful for regenerating it)
- if either of these options is specified the aliased program will not be run
(which means if the aliased program also uses these options (unlikely) it will never see them)
Porting to Unix
- When I first wrote this I did not bother to make a Unix version as Unix already has aliases. But as I think about it, this might not be a bad idea. Whereas aknist all Unix shells have aliases, the way they are implemented differs from shell to shell. Also, as mentioned above, they are not copied to subshells (as the Unix PATH variable is).
- For these reasons I think I will port mkalias to Unix. I'll only port the current version, though, that generates a C file because, unlike Windows, Unix runs on many different computer architectures and there would be no point to generating a generic binary alias program.
Aliases on my system