< Day Day Up > |
9.4. AliasesAn alias is a C/TC shell user-defined abbreviation for a command. (For tcsh enhancements to the alias mechanism, see "TC Shell Aliases" on page 491.) Aliases are useful when a command has a number of options and arguments or the syntax is difficult to remember. Aliases set at the command line are not inherited by subshells. Aliases are normally set in the .cshrc or .tcshrc file. Because the .cshrc or .tcshrc is executed when a new shell is started, any aliases set there will get reset for the new shell. Aliases may also be passed into shell scripts, but will cause potential portability problems unless they are directly set within the script. 9.4.1 Listing AliasesThe alias built-in command lists all set aliases. The alias is printed first, followed by the real command or commands it represents. Example 9.20.% alias co compress cp cp –i ls1 enscript –B –r –Porange –f Courier8 !* & mailq /usr/lib/sendmail –bp mroe more mv mv –i rn /usr/spool/news/bin/rn3 uc uncompress uu uudecode vg vgrind –t –s11 !:1 | lpr –t weekly (cd /home/jody/ellie/activity; ./weekly_report; echo Done) EXPLANATION The alias command lists the alias (nickname) for the command in the first column and the real command the alias represents in the second column. 9.4.2 Creating AliasesThe alias command is used to create an alias. The first argument is the name of the alias, the nickname for the command. The rest of the line consists of the command or commands that will be executed when the alias is executed. Multiple commands are separated by a semicolon, and commands containing spaces and metacharacters are surrounded by single quotes. Example 9.21.1 % alias m more 2 % alias mroe more 3 % alias lF 'ls -alF' 4 % alias cd 'cd \!*; set prompt = "$cwd >"' % cd .. /home/jody > cd / # New prompt displayed / > EXPLANATION
9.4.3 Deleting AliasesThe unalias command is used to delete an alias. To temporarily turn off an alias, the alias name is preceded by a backslash. Example 9.22.1 % unalias mroe 2 % \cd .. EXPLANATION
9.4.4 Alias LoopAn alias loop occurs when an alias definition references another alias that references back to the original alias. Example 9.23.1 % alias m more 2 % alias mroe m 3 % alias m mroe # Causes a loop 4 % m datafile Alias loop. EXPLANATION
|
< Day Day Up > |