2.7 C Shell Setup Files Aren't Read When You Want Them to Be?The C shell reads its .cshrc , .login , and .logout setup files at particular times (2.2 ) . Only "login" C shells (2.8 ) will read the .login and .logout files. Back when csh was designed, this restriction worked fine. The shell that started as you logged in was flagged as a login shell, and it read all three files. You started other shells (shell escapes, shell scripts, etc.) from that login shell, and they would read only .cshrc . Now, UNIX has interactive shells started by window systems (like xterm (1.31 ) ), remote shells (like rsh (1.33 ) ), and other shells that might need some things set from the .login or .logout files. Depending on how these shells are invoked, these might not be login shells - so they might read only .cshrc . How can you handle that? Putting all your setup commands in .cshrc isn't good because all subshells (38.4 ) read it... you definitely don't want to run terminal-setting commands like tset during shell escapes! To handle problems at login time, put almost all of your setup commands in .cshrc instead of .login . After the "login-only" commands have been read from .cshrc , set the ENV_SET environment variable (6.1 ) as a flag. (There's nothing special about this name. You can pick any name you want.) The shell will copy the "flag" variable to subshells and the .cshrc can test for it - if the variable exists, the login-only commands are skipped. That'll keep the commands from being read again in a shell escape. Here are parts of a .cshrc that show the idea:
You should put a comment in the .login file to explain what you've done. The .logout file should probably be read only once - when your last ("top-level") shell exits. If your top-level shell isn't a login shell, you can make it read .logout anyway. Here's how. First, along with the previous fixes to your .cshrc file, add an alias that will read your .logout file when you use the exit command. Also set the ignoreeof variable (3.5 ) to force you to use the exit command when you log out. Now the chunk of your .cshrc will look like:
- |
|