< Day Day Up > |
9.17. TC Shell AliasesAn alias is a TC shell user-defined abbreviation for a command. Aliases are useful if 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 .tcshrc file. Because the .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. The TC shell has some additional preset aliases, which remain undefined until you define them. They are: beepcmd, cwdcmd, periodic, and precomd. These aliases are listed and defined in "Special tcsh Aliases" on page 494. 9.17.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.94.> alias apache $HOME/apache/httpd -f $HOME/apache/conf/httpd.conf co compress cp cp –i ls1 enscript –B –r –Porange –f Courier8 !* & mailq /usr/lib/sendmail –bp mc setenv MC '/usr/bin/mc -P !*'; cd $MC; unsetenv MC mroe more mv mv –i 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.17.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. FORMAT alias alias aliasname command alias aliasname 'command command(s)' unalias aliasname Example 9.95.1 > alias m more 2 > alias mroe more 3 > alias lf ls-F 4 > alias cd 'cd \!*; set prompt = "%/ > "' 5 > cd .. 6 /home/jody > cd / # new prompt displayed / > 7 > set tperiod = 60 > alias periodic 'echo You have worked an hour, nonstop' 8 > alias Usage 'echo "Error: \!* " ; exit 1' EXPLANATION
9.17.3 Deleting AliasesThe unalias command is used to delete an alias. To temporarily turn off an alias, precede the alias name by a backslash. Example 9.96.1 > unalias mroe 2 > \cd .. EXPLANATION
9.17.4 Alias LoopAn alias loop occurs when an alias definition references another alias that references back to the original alias. Example 9.97.1 > alias m more 2 > alias mroe m 3 > alias m mroe # Causes a loop 4 > m datafile Alias loop. EXPLANATION
9.17.5 Special tcsh AliasesIf set, each of the TC shell aliases executes automatically at the indicated time. They are all initially undefined.
|
< Day Day Up > |