start up of C shell
After the csh program starts, it is programmed to execute two files
in the user's home directory: the .cshrc file
and then the .login file. These files allow
users to initialize their own environments.
The .cshrc file
the .cshrc file contains C shell variable settings and is executed
every a csh subshell is started. aliases and history are normally set here.
set noclobber
set ignoreeof set history=25 set savehist=5 set prompt=x7f\! stardust >" set filec fignore=(.0) set cdpath=(/home/joy/bin /usr/bin) alias m more alias status '(date; du -s)' alias cd 'cd\!*; set prompt=x7f<$cwd>"' |
avoid remove file using redirection
avoid log out with Ctrl-d the last 25 command in history cmd history saved after log out exclude files in filename completion
|
The .login file
The .login file is executed one time when user first log on. It normally
contains environment variables and terminal settings. It is the file where
window applications are usually started. Since environment variables are
inherited by processes spawned from this shell and only need to be set
once, and terminal settings do not have to be reset for every process,
those settings belong in the .login file.
setenv TERM sun
setenv OPENWIN /usr/local/ow3 set path=(4usr/bin /usr/local) echo " welcome aboard " if("'tty'"=="/dev/console") then echo "use openwindows?" sleep 5 $OPENWIN/bin/openwin endif /usr/games/fortuen |
set environment variable TERM
variable for window application search path |
The rehash command
The shell builds an internal hash table consisting of the contents
of the directories listed in the search path. If dot is in the search path,
the files in the dot directory, the current working directory, are not
put on the hash table. For efficiency, the shell
uses the hash table to find commands that are typed at the command line,
rather than searching the path each time. If a new command is added
to one of the directories already listed in the search path, the internal
hash table must be recomputed. This is done by typeing
%rehash
The hash table is also automatically recomputed when you change your
path at the prompt or start another shell.
The hashstat command
The hashstat command displays performance statistics to show the effectiveness
of its search for commands from the hash table.
The source command
The source command is a shell build-in command, that is, part of the
shell's internal code. It is used to execute a command or set of commands
from a file.
%source .login
The Shell prompts
The C Shell has two prompts: the primary prompt (%) and the secondary
prompt (?).
% set prompt = "$LOGNAME>"
The secondary prompt appears when you are writing online scripts at
the prompt. Whenever shell programming constructs are entered, followed
by a new line, the secondary prompt appears and continues to appear until
the construct is properly terminated.
% foreach pal (joe tom ann)
? mail $pal < memo ? end % |
Command Grouping
A command line can consist of multiple commands. Each command is separated
by a semicolon and the command line is terminated with a new line.
% ls; pwd; cal 1995
% (ls; pwd; cal 1997) > outputfile
Conditional execution of commands
With conditional execution, two command strings are separated ty &&
or ||
% grep '^tom' /etc/passwd && mail tom <letter
If first command is successful, the second command after the &&
is executed
% grep '^tom' /etc/passwd || echo "tom is not a user here"
If first command fails(has a non zero exit status), the second command
after || is executed
Command in background
%man xview | lp&
Reexecuting commands
If you type !!, the last command is reexecuted. If you type ! followed
by a number, the number is associated with the command from the history
list and the command is executed. If you type ! followed by a letter, the
last command that started with that letter is executed. The caret (^) is
also used as a shortcut method for editing the previous command.
%date
%!! %!3 %!d %dare %^r^t |
run date command
rerun data command type erro
|
Filename Completion: The filec variable
When running interactively, the C Shell provides a shortcut method
for typing a filename or user name. The build-in filec variable, when set,
is used for what is called filename completion. If you type the first few
significant characters of a file in the current working directory and press
the ESC key, the shell fills in the rest of the filename, provided that
there are not a number of other files beginning with the same characters.