home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 2.8 Identifying Login Shells Chapter 2
Logging In
Next: 2.10 Gotchas in set prompt Test
 

2.9 Speeding Up Your C Shell with set prompt Test

Every time you start a C shell - in a shell escape ( 30.26 ) , the su ( 22.22 ) command, a shell script, an at job ( 40.1 ) , etc.-the csh reads the .cshrc file in your home directory. Some of those shells are "noninteractive," which means the shell is running a single command or reading from a script file ( 1.5 ) - you won't be typing any commands yourself. If your .cshrc has commands like alias ( 10.2 ) , set cdpath ( 14.5 ) , and others that are only useful in interactive shells, it wastes time to make noninteractive shells read them.

You can tell the shell to skip commands that will only be used in interactive shells. Set up your .cshrc this way:





if
 
! $?
 







# COMMANDS FOR ALL C SHELLS:
set path = (...
whatever
...)
   ...
if (! $?prompt) goto cshrc_end

# COMMANDS FOR INTERACTIVE SHELLS ONLY:
alias foo bar
   ...
set cdpath = (~ ~joe/project)

cshrc_end:

Warning! The ! $?prompt succeeds only on noninteractive shells, when the shell hasn't set the prompt variable. On noninteractive shells, the command goto cshrc_end makes the shell skip to the line at the end of the file labeled cshrc_end: .

Of course, if you set your own prompt ( 7.1 ) , be sure to do it on some line below the ! $?prompt test. Otherwise, the test will always fail!

NOTE: Some books tell you to use a test like this instead:

if (! $?prompt) exit

# commands for interactive shells only:
   ...

But some C shells will log out when they see the exit command in a .cshrc file. Using goto cshrc_end is more portable.

Article 7.3 explains another problem that this $?prompt test solves.

- JP


Previous: 2.8 Identifying Login Shells UNIX Power Tools Next: 2.10 Gotchas in set prompt Test
2.8 Identifying Login Shells Book Index 2.10 Gotchas in set prompt Test

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru