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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 6.8 Shell Variables Chapter 6
Shell and Environment Variables
Next: 6.10 Running a Command with a Temporarily Different Environment
 

6.9 Special C Shell Variables

[Sorry, no articles about bash and tcsh variables. This book focuses on the "base" shells, sh and csh . csh variables work in tcsh , and many work (in slightly different forms) with bash too. For a complete list, check your bash or tcsh manpage. -JP]

The C shell recognizes and uses environment variables, but it also uses a great many simple shell variables (6.8 ) to control its own operation. These variables don't need to be put into the environment so they can be passed to subshells (38.4 ) , because every instance of the C shell always reads the .cshrc file (2.2 ) . Simple shell variables set there are thus propagated to every C shell.

Many of the special C shell variables are simply used as flags; that is, they need not be set to any particular value. The shell simply tests whether they exist or not. They are set simply by saying:

set variable

rather than:

set variable

=value

Here are some of the special variable names used by the C shell:

  • The cdpath (14.5 ) variable stores a list of directories. You can cd to subdirectories of these by typing just the subdirectory name.

  • If the echo (8.17 ) variable is set, the shell will show the command line, after all variable and history (11.7 ) substitutions, before executing it. (This is very handy for debugging scripts such as .cshrc .)

    If the verbose (8.17 ) variable is set, the shell will show the command line after history substitution but before any other substitutions.

    The Bourne shell -v and -x options (46.1 ) work like the verbose and echo variables.

  • If the filec or complete variable is set, the shell performs filename completion (9.8 ) . The fignore (9.9 ) variable makes filename completion skip filenames that end with certain characters like .o .

  • The cwd (14.13 ) variable shows the absolute pathname of the current directory. The cd , pushd , and popd commands set it.

  • The hardpaths (14.13 ) variable fixes errors in the cwd variable that occur when you cd through symbolic links.

  • Use the histchars (11.15 ) variable to set different history characters than exclamation point (! ) and caret (^ ).

  • The history (11.1 ) variable stores the number of shell command lines to save. The savehist (11.11 ) variable stores the number of lines of shell history to be saved when you log out. This amount of history is saved in a file called .history in your home directory, and the lines are restored the next time you log in.

  • If you set ignoreeof (3.5 ) , the shell won't respond to the end-of-file character (CTRL-d) and will require you to type logout or exit (38.4 ) to log out. This can save you from ending the shell accidentally (or logging out).

  • The shell can tell you about new electronic mail (1.33 ) or changes in other files with the mail (21.8 ) variable.

  • Stop the > redirection character from overwriting files with noclobber (13.6 ) .

  • The noglob variable stops wildcard expansion (15.1 ) . (There's an example in article 5.4 .)

  • Set nonomatch when you want the C shell to treat nonmatching wildcards like the Bourne shell does . (15.4 )

  • The notify (12.6 ) variable asks the shell to tell you right away if a background job finishes or is stopped.

  • The list of directories that the shell searches for commands is stored in path (6.5 ) .

  • Your login name from the USER or LOGNAME (6.3 ) environment variable is also stored in the C shell variable named user .

  • The shell's command-line prompt is set by the prompt (7.2 ) variable. (The PS1 (6.3 ) environment variable is the Bourne shell equivalent. You can set the Bourne shell's secondary prompt (9.13 ) , too, in PS2 .)

  • The exit status (44.7 ) of the last command is stored in the csh variable named status and the sh ? (question mark) variable.

  • If a job takes more CPU seconds than the number set in the time (39.3 ) variable, the csh will print a line of statistics about the job.

- JP , TOR


Previous: 6.8 Shell Variables UNIX Power Tools Next: 6.10 Running a Command with a Temporarily Different Environment
6.8 Shell Variables Book Index 6.10 Running a Command with a Temporarily Different Environment

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