next up previous contents
Next: C shell programming Up: Shell Programming Previous: A Real Life Example

C shell

C shell provides better variables than Bourne shell, it allows alias definitions, is more tolerant of mistakes and easier to use. If C shell is enabled in /etc/passwd, it executes the system wide command /etc/csh.login, then it executes $home/.login at session start and $home/.cshrc both at session start and for any new shell and script. In C shell the home directory is denoted also by ~. At session logout C shell executes ~.logout. The shell you are in is inquired by:

> echo $shell

A job may be suspended by <Ctrl>-z. Suspended jobs are manipulated by the builtin commands jobs, fg, bg. Background jobs are accessed by %job_no or %job_name if job_name is unique. The wild character ? can be used in job names. Both job_no and job_name are listed by jobs. Job pointer brief forms are:


%+ 		 current job 
%- previous job
%% synonimous of current job

C shell environment is queried by env for system wide variables and by set for local definitions. If the local variable filec is set, C shell enables file name completion with the <ESC> character, that is represented by \framebox{$\wedge$ } in the following sections.

% set | grep filec              # check whether filec is set
%                               # filec not set
% set filec                     # set filec (no value required)
% set | grep filec              # verify that filec is set
filec
% vi adv^[[2xxx                 # try name completion
[23~vi: Command not found.      # failure for bad term setting
% vt100                         # set term as vt100
% vi adv<esc>                   # try again
% vi advxxx                     # sucess
"advxxx" 1 line, 5 characters
date
~
~
!wq
%
In the above example, file name completion fails because of the wrong transaltion of the <esc> code due to an incorret setting of the terminal. A solution is the execution of the vt100 script listed below.

#!/bin/sh
cat <<!
^[[?38l^[[61"p
!

C shell commands may be recalled through the history feature, that keeps an enumerated list of the last n commands provided that the shell history variable is set to n:

% set history = 20              # set history buffer size
% history                       # list history buffer
    62  set TERM=vt100
    63  set editmode = vi
    64  vi tapes.f
    ....................
    74  alias H history
%
In this way the history command lists the last 20 typed commands. Typing !64 recalls and executes command 64 of the current history list where \framebox{!} is the recall symbol, \framebox{!!} recalls the last typed command, !vi recalls the previous command matching the string.

As the immediate execution of a command may be very dangerous, C shell should always be set to editmode either choosing emacs or vi as shown in the above history line 63. If editmode is set, the recalled command is typed and the shell waits for user action. In this way the user is enabled to edit the command using either vi or emacs editing rules and the command is executed only after <ret>.

If problems arise using special keys like <ctrl-D>, check the binding section of man csh for key binding that is handled by the bind-to-key shell command. Single character bindings, default binding tables and keyboard macro are fully described in the man pages. Put permanent bindings in the file ~/.bindings



 
next up previous contents
Next: C shell programming Up: Shell Programming Previous: A Real Life Example
Marisa Luvisetto
2001-02-05