Section 8.2. Startup


[Page 296 (continued)]

8.2. Startup

The C shell is a regular C program whose executable file is stored as "/bin/tcsh". If your chosen shell is "/bin/tcsh", an interactive C shell is invoked automatically when you log into a Linux system. You may also invoke a C shell manually from a script or from a terminal by using the command tcsh. tcsh has several command-line options that are described at the end of this chapter.

When a C shell is started as a login shell, a global login initialization file, "/etc/login" may also be executed. This is useful for setting up environment variables (such as PATH) to contain information about the local environment.

When a C shell is invoked, the startup sequence is different for login shells and nonlogin shells (Figure 8-1).


[Page 297]

Figure 8-1. C shell startup sequence.

Step

Shell type

Action

1

both

Execute commands in $HOME/.tcshrc or $HOME/.cshrc if it exists.

2

login only

Execute commands in global login initialization file if it exists.

3

login only

Execute commands in $HOME/.login if it exists.


Note that the ".tcshrc" (or if not found, ".cshrc") file is run before either type of login initialization file. This may seem counterintuitive and has been the cause of much unexpected behavior when users are crafting their initialization files. The way to keep this straight is to remember that the C shell always runs its own initialization file immediately upon starting, then determines if the shell is a login shell which would require running the other initialization files.

Once an interactive shell starts and finishes running all the appropriate initialization files, it displays its prompt and awaits user commands. The standard C shell prompt is %, although it may be changed by setting the local variable $prompt, described shortly.

The ".login" file typically contains commands that set environment variables such as TERM, which contains the type of your terminal, and PATH, which tells the shell where to search for executable files. Put things in your ".login" file that need to be set only once (environment variables whose values are inherited by other shells) or make sense only for an interactive session only (like specifying terminal settings). Here's an example of a ".login" file:

echo -n "Enter your terminal type (default is vt100): " set termtype = $< set term = vt100 if ("$termtype" != "") set term = "$termtype" unset termtype set path=(. /bin /usr/bin /usr/local/bin ) stty erase "^?" kill "^U" intr "^C" eof "^D" crt crterase set cdpath = (~) set history = 40 set notify set prompt = "! % " set savehist = 32 


The ".tcshrc" file generally contains commands that set common aliases (discussed later) or anything else that only applies to the current shell. The "rc" suffix stands for "run commands." Here's an example of a ".tcshrc" file:

alias h history alias ll ls -l alias ls ls -F alias rm rm -i alias m more 





Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

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