Much of the power of TCC comes together in aliases, which give you the ability to create your own commands. An alias is a name that you select for a command or group of commands. Simple aliases substitute a new name for an existing command. More complex aliases can redefine the default settings of internal or external commands, operate as very fast in-memory batch files, and perform commands based on the results of other commands. TCC also supports Directory Aliases, a shorthand way of specifying pathnames. TCC supports either a local alias list that is only visible to the current TCC session, or a global alias list that is shared among all TCC sessions.
This section shows you some examples of the power of aliases. See the ALIAS command for complete details about writing your own aliases.
The simplest type of alias gives a new name to an existing command. For example, you could create a command called R (for Root directory) to switch to the root directory this way:
alias r=cd \
After the alias has been defined this way, every time you type the command R, you will actually execute the command CD \.
Aliases can also create customized versions of commands. For example, the DIR command can sort a directory in various ways. You can create an alias called DE that means "sort the directory by filename extension, and pause after each page while displaying it" like this:
alias de=dir /oe /p
Aliases can be used to execute sequences of commands as well. The following command creates an alias called MUSIC which saves the current drive and directory, changes to the SOUNDS directory on drive C, runs the program E:\MUSIC\PLAYER.EXE, and, when the program terminates, returns to the original drive and directory (enter this on one line):
alias music=`pushd c:\sounds & e:\music\player.exe & popd`
This alias is enclosed in back-quotes because it contains multiple commands. You must use the back-quotes whenever an alias contains multiple commands, environment variables, parameters (see below), redirection, or piping. See the ALIAS command for full details.
When an alias contains multiple commands, the commands are executed one after the other. However, if any of the commands runs an external Windows application (such as the fictitious PLAYER.EXE shown above), you must be sure the alias will wait for the application to finish before continuing with the other commands. See Waiting for Applications to Finish for additional details.
Aliases can be nested; that is, one alias can invoke another. For example, the alias above could also be written as:
alias music=`pushd c:\sounds & play & popd`
If you enter MUSIC as a command, TCC executes the PUSHD command, detects that the next command (PLAY) is another alias and executes the program E:\MUSIC\PLAYER.EXE, and, when that program exits, returns to the first alias, executes the POPD command, and returns to the prompt.
You can use aliases to change the default options for both internal commands and external commands. Suppose that you always want the DEL command to prompt before it erases a file:
alias del=*del /p
An asterisk * is used in front of the second DEL to tell TCC to use the original internal command, not an alias. See Temporarily Disabling Aliases for more information about this use of the asterisk.
You may have a program on your system that has the same name as an internal command. Normally, if you type the command name, you will start the internal command rather than the program you desire, unless you explicitly add the program's full path on the command line. For example, if you have a program named DESCRIBE.EXE in the C:\WUTIL directory, you could run it with the command C:\WUTIL\DESCRIBE.EXE. However, if you simply type DESCRIBE, the internal DESCRIBE command will be executed instead. Aliases give you two simple ways to get around this problem.
First, you could define an alias that runs the program in question, but using a different name:
Another approach is to use an alias to rename the internal command and use its original name for the external program. The following example creates the alias FILEDESC for the DESCRIBE command, and then uses a second alias to run DESCRIBE.EXE whenever you type DESCRIBE:
You can also assign an alias to a key, so that every time you press the key, the command will be invoked. You do so by naming the alias with an at sign [@] followed by a key name. After you enter this next example, you will see a 2-column directory with paging whenever you press Shift-F5 followed by Enter:
alias @Shift-F5=*dir /2/p
This alias will put the DIR command on the command line when you press Shift-F5, then wait for you to enter file names or additional switches. You must press Enter when you are ready to execute the command. To execute the command immediately, neither displaying it on the command line, nor waiting for you to press Enter, use two @ signs at the start of the alias name:
alias @@Shift-F5=*dir /2/p
The next example clears the window whenever you press Ctrl-F2:
Aliases have many other capabilities as well. The next example creates a simple command line calculator. Once you have entered the example, you can type CALC 4*19, for example, and you will see the answer:
alias calc=`echo The answer is: %@eval[%$]`
Our last example in this section creates an alias called IN. It temporarily changes directories, runs an internal or external command, and then returns to the current directory when that command is finished:
alias in=`pushd %1 & %2$ & popd`
Now if you type:
in c:\sounds play furelise.wav
you will change to the C:\SOUNDS subdirectory, execute the command PLAY FURELISE.WAV, and then return to the current directory.
The above example uses two parameters: %1 means the first parameter on the command line, and %2$ means the second and all subsequent parameters.
Aliases can use command line parameters or parameters like those in batch files. The command line parameters are numbered from %0 to %511. (%0 contains the alias name.) You can use double quotes to pass spaces, tabs, commas, and other special characters in an alias parameter; see Parameter Quoting for details. Alias examples in this section assume the TCCdefault of ParameterChar=$.
Parameters that are referred to in an alias, but which are missing on the command line, appear as empty strings inside the alias. For example, if you only put two parameters on the command line, any reference in the alias to %3 or any higher-numbered parameter will be interpreted as an empty string.
The parameter %n$ has a special meaning. TCC interprets it to mean "the entire command line, from parameter n to the end." If n is not specified, it has a default value of 1, so %$ means "the entire command line after the alias name."
The parameter %-n$ means "the command line from parameter 1 to n - 1".
The special parameter %# contains the number of command line parameters.
Aliases cannot use indirect access to command parameters, e.g., %[%n] (where n is a parameter number) does not return the selected parameter.