Entering and Leaving the TC Shell


You can execute tcsh by giving the command tcsh. If you are not sure which shell you are using, use the ps utility to find out. It shows whether you are running tcsh, bash, sh (a copy of bash), or possibly another shell. The finger command followed by your username displays the name of your login shell, which is stored in the passwd database. If you want to use tcsh as a matter of course, you can use the chsh (change shell) utility (page 448) to change your login shell. The shell you specify will be in effect for your next login and all subsequent logins until you specify a different login shell.

Tip: Shell game

When you are working with an interactive TC Shell, if you run a script in which # is not the first character of the script and you call the script directly (without preceding its name with tcsh), tcsh calls the sh copy of bash to run the script. The following script was written to be run under tcsh but, when called from a tcsh command line, is executed by bash. The set builtin (page 568) works differently under bash and tcsh. As a result the following example (from page 358) issues a prompt but does not wait for you to respond:

tcsh $ cat user_in echo -n "Enter input: " set input_line = "$<" echo $input_line tcsh $ user_in Enter input: 


Although in each case the examples are run from a tcsh command line, the following one calls tcsh explicitly so that tcsh executes the script and it runs correctly.

tcsh $ tcsh user_in Enter input: here is some input here is some input 



Tip: echo: getting rid of the RETURN

The tcsh echo builtin accepts either a n option or a trailing \c to get rid of the RETURN that echo normally displays at the end of a line. The bash echo builtin accepts only the n option (refer to "read: Accepts User Input" on page 571).


You can leave tcsh in several ways. The approach you choose depends on two factors: whether the shell variable ignoreeof is set and whether you are using the shell that you logged in on (your login shell) or another shell that you created after you logged in. If you are not sure how to exit from tcsh, press CONTROL-D on a line by itself with no leading SPACEs, just as you would to terminate standard input to another program. You will either exit or receive instructions on how to exit. If you have not set ignoreeof (page 363) and it has not been set for you in a startup file, you can exit from any shell by using CONTROL-D (the same procedure you use to exit from the Bourne Again Shell).

When ignoreeof is set, CONTROL-D does not work. The ignoreeof variable causes the shell to display a message telling you how to exit. You can always exit from tcsh by giving an exit command. A logout command allows you to exit from your login shell only.

Startup Files

When you log in on the TC Shell, it automatically executes various startup files. These files are normally executed in the order described in this section, but you can compile tcsh so that it uses a different order. You must have read access to a startup file to execute the commands in it.

/etc/csh.cshrc and /etc/csh.login

The shell first executes the commands in /etc/csh.cshrc and /etc/csh.login. Superuser can set up these files to establish systemwide default characteristics for tcsh users. They contain systemwide configuration information, such as the default path, the location to check for mail, and so on.

.tcshrc and .cshrc

Next the shell looks for ~/.tcshrc or, if it does not exist, ~/.cshrc (~/ is shorthand for your home directory). You can use these files to establish variables and parameters that are local to your shell. Each time you create a new shell, tcsh reinitializes these variables for the new shell. The following .tcshrc file sets several shell variables, establishes two aliases (page 344), and adds two new directories to pathone at the start of the list and one at the end:

tcsh $ cat ~/.tcshrc set noclobber set dunique set ignoreeof set history=256 set path = (~/bin $path /Developer/Tools) alias h history alias ll ls -l 


.history

Login shells rebuild the history list from the contents of ~/.history. If the histfile variable exists, tcsh uses the file that histfile points to in place of .history.

.login

Login shells read and execute the commands in ~/.login. This file contains commands that you want to execute once, at the beginning of each session. You can use setenv (page 353) to declare environment (global) variables here. You can also declare the type of terminal you are using and set some terminal characteristics in your .login file.

tcsh $ cat ~/.login setenv history 200 setenv mail /var/spool/mail/$user if ( -z $DISPLAY ) then        setenv TERM vt100    else        setenv TERM xterm endif stty erase '^h' kill '^u' -lcase tab3 date '+Login on %A %B %d at %I:%M %p' 


The preceding .login file establishes the type of terminal you are using by setting the TERM variable (the if statement [page 364] checks to see whether it is running under X11 [the DISPLAY variable is set under X11], to determine what value to assign to TERM). It then runs stty (page 854) to set terminal characteristics and date (page 701) to display the time you logged in.

/etc/csh.logout and .logout

The TC Shell runs the /etc/csh.logout and ~/.logout files, in that order, when you exit from a login shell. The following sample .logout file uses date to display the time you logged out. The sleep command ensures that echo has time to display the message before the system logs you out. The delay may be useful for dial-up lines that take some time to display the message.

tcsh $ cat ~/.logout date '+Logout on %A %B %d at %I:%M %p' sleep 5 





A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net