ch03 09


Gotchas in set prompt Test (Unix Power Tools, 3rd Edition) 3.9. Gotchas in set prompt Test Lots of users add an if (! $?prompt) exit test to their .cshrc files. It's gotten so common that some vendors add a workaround to defeat the test. For instance, some versions of the which command (Section 2.6) set the prompt variable so that it can see your aliases "hidden" inside the $?prompt test. I've also seen a version of at that starts an interactive shell to run jobs. If you've buried commands after if (! $?prompt) that should only be run on interactive shells or at login time, then you may have trouble. There are workarounds. What you'll need depends on the problem you're trying to work around. The version of which on the CD-ROM [see http://examples.oreilly.com/upt3] works without reading your .cshrc file, so there's no problem there. Here's a way to stop the standard which from reading parts of your .cshrc that you don't want it to read. The first time you log in, this scheme sets a CSHRC_READ environment variable (Section 35.3). The variable will be copied into all subshells (Section 24.4) (like the one that which starts). In subshells, the test if ($?CSHRC_READ) will branch to the end of your .cshrc file: if (! $?prompt) goto cshrc_end # COMMANDS BELOW HERE ARE READ ONLY BY INTERACTIVE SHELLS: alias foo bar ... if ($?CSHRC_READ) goto cshrc_end # COMMANDS BELOW HERE ARE READ ONLY AT LOGIN TIME: setenv CSHRC_READ yes ... cshrc_end: If you have a buggy version of at (Section 25.5) that runs jobs from interactive shells, make your own frontend to at (Section 29.1) that sets an environment variable named AT temporarily before it submits the at job. Add a test to your .cshrc that quits if AT is set: ( ) Section 43.7, \at Section 29.8 # at JOBS RUN INTERACTIVE SHELLS ON MY BUGGY VERSION OF UNIX. # WORKAROUND IS HERE AND IN THE at ALIAS BELOW: if ($?AT) goto cshrc_end ... alias at '(setenv AT yes; \at \!*)' ... cshrc_end: Most modern versions of at save a copy of your environment when you submit the job and use it when the at job is run. At that time, the AT environment variable will be set; the C shell will skip the parts of your .cshrc that you want it to. It's ugly, but it works. Those workarounds probably won't solve all the problems on your version of Unix, but I hope they'll give you some ideas. --JP and SJC 3.8. Setup Files Aren't Read When You Want?3.10. Automatic Setups for Different Terminals Copyright © 2003 O'Reilly & Associates. All rights reserved.

Wyszukiwarka

Podobne podstrony:
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03
ch03 (8)
ch03
ch03
ch03 (4)

więcej podobnych podstron