[Toc][Index]

ALIAS - Create or display aliases

 
 Purpose:    Create new command names that execute one or more commands or 
             redefine default options for existing commands; assign 
             commands to keystrokes; load or display the list of defined 
             alias names. 
             
 Format:     ALIAS [/P /R file ...] [name [=][value ]] 
             
             file :  One or more files to read for alias definitions. 
             name :  Name for an alias, or for the key to execute the 
             alias. 
             value :  Text to be substituted for the alias name. 
             
             /P(ause)                        /R(ead file) 
 
 See also:  UNALIAS. 
 Usage 
 The ALIAS command lets you create new command names or redefine internal 
 commands.  It also lets you assign one or more commands to a single 
 keystroke.  An alias is often used to execute a complex series of 
 commands with a few keystrokes or to create "in memory batch files" that 
 run much faster than disk-based batch files. 
 For example, to create a single-letter command D to display a wide 
 directory, instead of useing the longer DIR /W, you could use the 
 command: 

 
         [c:\] alias d = dir /w
 
 
 Now when you type a single d as a command, it will be translated into a 
 DIR /W command. 
 If you define aliases for commonly used application programs, you can 
 often remove the directories they're stored in from the PATH. For 
 example, if you use Quattro Pro and had the C:\QPRO directory in your 
 path, you could define the following alias: 

 
         [c:\] alias qpro = c:\qpro\q.exe
 
 
 With this alias defined, you can probably remove C:\QPRO from your PATH. 
  Quattro Pro will now load more quickly than it would if CMD.EXE had to 
 search the PATH for it.  In addition, the PATH can be shorter, which will 
 speed up searches for other programs. 
 If you apply this technique for each application program, you can often 
 reduce your PATH to just two or three directories containing utility 
 programs, and significantly reduce the time it takes to load most 
 software on your system.  Before removing a directory from the PATH, you 
 will need to define aliases for all the executable programs you commonly 
 use which are stored in that directory. 
 Aliases are stored in memory, and are not saved automatically when you 
 turn off your computer or end your current session.  See below for 
 information on saving and reloading your aliases. 
 Multiple Commands and Special Characters in Aliases 
 An alias can represent more than one command.  For example: 

 
         [c:\] alias letters = `cd \letters & text`
 
 
 creates a new command called LETTERS.  The command first uses CD to 
 change to a subdirectory called \LETTERS and then runs a program called 
 TEXT.  The ampersand [&] is the command separator and indicates that the 
 two commands are distinct and should be executed sequentially. 
 Aliases make extensive use of the command separator, and the parameter 
 character, and may also use the escape character. These characters differ 
 between CMD.EXE, 4DOS, 4NT, and Take Command.  In the text and examples 
 below, we use the CMD.EXE characters.  If you want to use the same 
 aliases under different command processors, see Special Character 
 Compatibility. 
 When you type alias commands at the command line or in a batch file, you 
 must use back quotes [`] around the definition if it contains multiple 
 commands, parameters (discussed below), environment variables, 
 redirection, or piping.  The back quotes prevent premature expansion of 
 these arguments.  You may use back quotes around other definitions, but 
 they are not required. (You do not need back quotes when your aliases are 
 loaded from an ALIAS /R file; see below for details.)  The examples above 
 and below include back quotes only when they are required. 
 Nested Aliases 
 Aliases may invoke internal commands, external commands, or other 
 aliases.  (However, an alias may not invoke itself, except in special 
 cases where an IF or IFF command is used to prevent an infinite loop.) 
  The two aliases below demonstrate alias nesting (one alias invoking 
 another).  The first line defines an alias which runs a program called 
 WP.EXE that is in the E:\WP60\ subdirectory.  The second alias changes 
 directories with the PUSHD command, runs the WP alias, and then returns 
 to the original directory with the POPD command: 

 
         [c:\] alias wp = e:\wp60\wp.exe
         [c:\] alias w = `pushd c:\wp & wp & popd`
 
 
 The second alias above could have included the full path and name of the 
 WP.EXE program instead of calling the WP alias. However, writing two 
 aliases makes the second one easier to read and understand, and makes the 
 first alias available for independent use.  If you rename the WP.EXE 
 program or move it to a new directory, only the first alias needs to be 
 changed. 
 Temporarily Disabling Aliases 
 If you put an asterisk [*] immediately before a command in the value of 
 an alias definition (the part after the equal sign), it tells CMD.EXE not 
 to attempt to interpret that command as another (nested) alias.  An 
 asterisk used this way must be preceded by a space or the command 
 separator and followed immediately by an internal or external command 
 name. 
 By using an asterisk, you can redefine the default options for any 
 internal or external command.  For example, suppose that you always want 
 to use the DIR command with the /2 (two column) and /P (pause at the end 
 of each page) options.  The following line will do just that: 

 
         [c:\] alias dir = *dir /2/p
 
 
 If you didn't include the asterisk, the second DIR on the line would be 
 the name of the alias itself, and CMD.EXE would repeatedly re- invoke the 
 DIR alias, rather than running the DIR command.  This would cause an 
 "Alias loop" or "Command line too long" error. 
 An asterisk also helps you keep the names of internal commands from 
 conflicting with the names of external programs.  For example, suppose 
 you have a program called LIST.COM.  Normally, the internal LIST command 
 will run anytime you type LIST.  But two simple aliases will give you 
 access to both the LIST.COM program and the LIST command: 

 
         [c:\] alias list = c:\util\list.com
         [c:\] alias display = *list
 
 
 The first line above defines LIST as an alias for the LIST.COM program. 
  If you stopped there, the external program would run every time you 
 typed LIST and you would not have easy access to the internal LIST 
 command.  The second line renames the internal LIST command as DISPLAY. 
  The asterisk is needed in the second command to indicate that the 
 following word means the internal command LIST, not the LIST alias which 
 runs your external program. 
 Another way to understand the asterisk is to remember that a command is 
 always checked for an alias first, then for an internal or external 
 command, or a batch file.  The asterisk at the beginning of a command 
 name simply skips over the usual check for aliases when processing that 
 command, and allows the command processor to go straight to checking for 
 an internal command, external command, or batch file. 
 You can also use an asterisk before a command that you enter at the 
 command line or in a batch file.  If you do, that command won't be 
 interpreted as an alias.  This can be useful when you want to be sure you 
 are running the true, original command and not an alias with the same 
 name, or temporarily defeat the purpose of an alias which changes the 
 meaning or behavior of a command. 
 You can also disable aliases temporarily with the SETDOS /X command. 
 Partial Alias Names 
 You can also use an asterisk in the name of an alias.  When you do, the 
 characters following the asterisk are optional when you invoke the alias 
 command.  (Use of an asterisk in the alias name is unrelated to the use 
 of an asterisk in the alias value discussed above.)  For example, with 
 this alias: 

 
         [c:\] alias wher*eis = dir /sp
 
 
 the new command, WHEREIS, can be invoked as WHER, WHERE, WHEREI, or 
 WHEREIS.  Now if you type: 

 
         [c:\] where myfile.txt
 
 
 The WHEREIS alias will be expanded to the command: 

 
         dir /sp myfile.txt
 
 
 Keystroke Aliases 
 If you want to assign an alias to a keystroke, use the keyname on the 
 left side of the equal sign, preceded by an at sign [@]. For example, to 
 assign the command DIR /W to the F5 key, type 

 
         [c:\] alias @F5 = dir /w
 
 
 See Keys and Key Names for a complete listing of key names and a 
 description of the key name format. 
 When you define keystroke aliases, the assignments will only be in effect 
 at the command line, not inside application programs.  Be careful not to 
 assign aliases to keys that are already used at the command line (like F1 
 for Help).  The command-line meanings take precedence and the keystroke 
 alias will never be invoked.  If you want to use one of the command-line 
 keys for an alias instead of its normal meaning, you must first disable 
 its regular use with the NormalKey or NormalEditKey directives in your 
 .INI file. 
 If you define a keystroke alias with a single at sign as shown above, 
 then, when you press the F5 key, the value of the alias (DIR /W above) 
 will be placed on the command line for you.  You can type additional 
 parameters if you wish and then press Enter to execute the command.  With 
 this particular alias, you can define the files that you want to display 
 after pressing F5 and before pressing Enter to execute the command. 
 If you want the keystroke alias to take action automatically without 
 waiting for you to edit the command line or press Enter, you can begin 
 the definition with two at signs [@@]. CMD.EXE will execute the alias 
 "silently," without displaying its text on the command line.  For 
 example, this command will assign an alias to the F6 key that uses the 
 CDD command to take you back to the previous default directory: 

 
         [c:\] alias @@f6 = cdd -
 
 
 When you define keystroke aliases, the assignments will only be in effect 
 at the command line, not inside application programs.  Be careful not to 
 assign aliases to keys that are already used at the command line (like F1 
 for Help).  The command-line meanings take precedence and the keystroke 
 alias will never be invoked.  If you want to use one of the command-line 
 keys for an alias instead of its normal meaning, you must first disable 
 its regular use with the NormalKey or NormalEditKey directives in your 
 .INI file. 
 You can also define a keystroke alias by using "@" or "@@" plus a scan 
 code for one of the permissible keys (see the Reference Tables for a list 
 of scan codes).  In most cases it will be easier to use key names.  Scan 
 codes should only be used with unusual keyboards where a key name is not 
 available for the key you are using. 
 Displaying Aliases 
 If you want to see a list of all current ALIAS commands, type: 

 
         [c:\] alias
 
 
 You can also view the definition of a single alias.  For example, if you 
 want to see the definition of the alias LIST, you can type: 

 
         [c:\] alias list
 
 
 Saving and Reloading Your Aliases 
 You can save your aliases to a file called ALIAS.LST this way: 

 
         [c:\] alias > alias.lst
 
 
 You can then reload all the alias definitions in the file the next time 
 you boot up with the command: 

 
         [c:\] alias /r alias.lst
 
 
 This is much faster than defining each alias individually in a batch 
 file.  If you keep your alias definitions in a separate file which you 
 load when your system starts, you can edit them with a text editor, 
 reload the edited file with ALIAS /R, and know that the same alias list 
 will be loaded the next time you boot your computer. 
 When you define aliases in a file that will be read with the ALIAS /R 
 command, you do not need back quotes around the value, even if back 
 quotes would normally be required when defining the same alias at the 
 command line or in a batch file. 
 To remove an alias, use the UNALIAS command. 
 Alias Parameters 
 Aliases can use command-line arguments or parameters like those in batch 
 files.  The command-line arguments are numbered from %0 to %127.  %0 
 contains the alias name.  It is up to the alias to determine the meaning 
 of the other parameters.  You can use quotation marks to pass spaces, 
 tabs, commas, and other special characters in an alias parameter; see 
 Argument Quoting for details. 
 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 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.  CMD.EXE interprets it to mean 
 "the entire command line, from argument 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 special parameter %# contains the number 
 of command-line arguments. 
 For example, the following alias will change directories, perform a 
 command, and return to the original directory: 

 
         [c:\] alias in `pushd %1 & %2$ & popd`
 
 
 When this alias is invoked as: 

 
         [c:\] in c:\comm mycomm /zmodem /56K
 
 
 the first parameter, %1, has the value c:\comm. %2 is mycomm, %3 is 
 /zmodem, and %4 is /56K.  The command line expands into these three 
 separate commands: 

 
         pushd c:\comm
         mycomm /zmodem /56K
         popd
 
 
 This next example uses the IFF command to redefine the defaults for SET. 
  It should be entered on one line: 

 
         [c:\] alias set = `iff %# == 0 then & *set /p
              & else & *set %& & endiff`
 
 
 This modifies the SET command so that if SET is entered with no 
 arguments, it is replaced by SET /P (pause after displaying each page), 
 but if SET is followed by an argument, it behaves normally. Note the use 
 of asterisks (*set) to prevent alias loops. 
 If an alias uses parameters, command-line arguments will be deleted up to 
 and including the highest referenced argument.  For example, if an alias 
 refers only to %1 and %4, then the first and fourth arguments will be 
 used, the second and third arguments will be discarded, and any 
 additional arguments beyond the fourth will be appended to the expanded 
 command (after the value portion of the alias).  If an alias uses no 
 parameters, all of the command-line arguments will be appended to the 
 expanded command. 
 Aliases also have full access to all variables in the environment, 
 internal variables, and variable functions.  For example, you can create 
 a simple command-line calculator this way: 

 
         [c:\] alias calc = `echo The answer is: %@eval[%&]`
 
 
 Now, if you enter: 

 
         [c:\] calc 5 * 6
 
 
 the alias will display: 

 
         The answer is: 30
 
 
 Expanding Aliases at the Prompt 
 You can expand an alias on the command line and view or edit the results 
 by pressing Ctrl-F after typing the alias name, but before the command is 
 executed.  This replaces the alias with its contents, and substitutes 
 values for each alias paramter, just as if you had pressed the Enter key. 
  However, the command is not executed; it is simply redisplayed on the 
 command line for additional editing. 
 Ctrl-F is especially useful when you are developing and debugging a 
 complex alias, or if you want to make sure that an alias that you may 
 have forgotten won't change the effect of your command. 
 Local and Global Aliases 
 The aliases can be stored in either a "local" or "global" list. 
 With a local alias list, any changes made to the aliases will only affect 
 the current copy of CMD.EXE.  They will not be visible in other shells or 
 other sessions. 
 With a global alias list, all copies of CMD.EXE will share the same alias 
 list, and any changes made to the aliases in one copy will affect all 
 other copies.  This is the default. 
 You can control the type of alias list with the LocalAliases directive in 
 the .INI file, and with the /L and /LA options of the START command. 
 Whenever you start a secondary shell which uses a local alias list, it 
 inherits a copy of the aliases from the previous shell. However, any 
 changes to the aliases made in the secondary shell will affect only that 
 shell.  If you want changes made in a secondary shell to affect the 
 previous shell, use a global alias list in both shells. 
 Retaining Global Aliases with SHRALIAS 
 If you select a global alias list for CMD.EXE you can share the aliases 
 among all copies of CMD.EXE running in any session.  When you close all 
 CMD.EXE sessions, the memory for the global alias list is released, and a 
 new, empty alias list is created the next time you start CMD.EXE. 
 If you want the alias list to be retained in memory even when no command 
 processor session is running, execute the SHRALIAS command, which loads a 
 program to perform this service for the global alias list, the global 
 command history list, and the global directory history. 
 You may find it convenient to execute SHRALIAS from your 4START file, or 
 from STARTUP.CMD. 
 SHRALIAS retains the alias list in memory, but cannot preserve it when 
 OS/2 itself is shut down.  To save your aliases when restarting OS/2, you 
 must store them in a file and reload them after the system restarts.  For 
 details on how to do so, see Saving and Reloading Your Aliases (above). 
 The UNKNOWN_CMD Alias 
 If you create an alias with the name UNKNOWN_CMD, it will be executed any 
 time CMD.EXE would normally issue an "Unknown command" error message. 
  This allows you to define your own handler for unknown commands.  When 
 the UNKNOWN_CMD alias is executed, the command line which generated the 
 error is passed to the alias for possible processing.  For example, to 
 display the command that caused the error: 

 
         alias unknown_cmd `echo Error in command "%&"`
 
 
 If the UNKNOWN_CMD alias contains an unknown command, it will call itself 
 repeatedly.  If this occurs, the command processor will loop up to 10 
 times, then display an "UKNOWN_CMD loop" error. 
 Options 
    /P:     (Pause) This option is only effective when ALIAS is used to 
            display existing definitions.  It pauses the display after 
            each page and waits for a keystroke before continuing (see 
            Page and File Prompts). 
    /R:     (Read file) This option loads an alias list from a file. The 
            format of the file is the same as that of the ALIAS display: 

            
                    name=value
            
            
            where name is the name of the alias and value is its value. 
             You can use an equal sign [=] or space to separate the name 
            and value.  Back quotes are not required around the value. 
             You can add comments to the file by starting each comment 
            line with a colon [:].  You can load multiple files with one 
            ALIAS /R command by placing the names on the command line, 
            separated by spaces: 

            
                    [c:\] alias /r alias1.lst alias2.lst
            
            
            Each definition in an ALIAS /R file can be up to 2047 
            characters long. The definitions can span multiple lines in 
            the file if each line, except the last, is terminated with an 
            escape character. 
 

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs