TC Shell

Back Up Next

horizontal rule

Home
Chapter 1
Chapter 2
Chapter 3
The Shell
Parameters and Variables
The Bourne Again Shell
Grep and AWK
Control Structures
Shell Program examples
TC Shell
Programming tools
Networking and the Internet

 

TC Shell

tcsh  - C shell with file name completion and command line editing   

tcsh is an enhanced but completely compatible  version  of the  Berkeley  UNIX C shell, csh(1).  It is a command language interpreter usable  both  as  an  interactive  login shell and a shell script command processor.  It includes a command-line editor,  programmable  word  completion, spelling correction,  a  history mechanism,  job control and a C-like  syntax.

bullet

UNIX shell differences and how to change your shell   

bullet

tcsh

bullet

man page for tcsh (1)

Startup and shutdown  

A login shell begins by executing commands from the system:

1.     /etc/csh.cshrc (# System wide environment and startup programs for csh users ) and /etc/csh.login 

2.     then executes commands  from  files  in the user's home directory: first  ~/.tcshrc (+) or, if ~/.tcshrc  is  not  found,  ~/.cshrc, then  ~/.history (or the value of the histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the value of  the  dirsfile shell variable) (+).  The shell may read      /etc/csh.login before instead of after /etc/csh.cshrc, and  ~/.login before instead of after ~/.tcshrc or ~/.cshrc and  ~/.history, if so compiled

                                    

Some features of C-shell (tcsh)

   §        History

§        Aliases

§        Job control

§        Filename substitution

Changing shells

temporary

bash$ tcsh

permanent

     If you want to make changes permanent to your login shell until changed again:

     [wmorales@rc33uxas01 wmorales]$ chsh (change shell)

Changing shell for wmorales.
Password: ********
New shell [/bin/bash]: /bin/tcsh

History (also found in bash)

% history  

% set history=10   (This will limit the history to the last 10 commands)

% set savehist=5        (limits the number of commands to save across login sessions. This will remember the five most recent commands.)

  Executing a previous event

 

            % set prompt = ‘[\!]’ (this will change your prompt so you can see history line numbers)

         % !event#    (executes the event%)

         % !!                (executes the previous event)

         % !cat           (executes last event that started with cat)

         % !?test?     (executes last event that had the string test)

           70% echo apple grape orange pear

           71% echo !70:2 (it will recall from history line 70 the second argument)

                                    ^ = word #1     70 the second argument)
                                    $ = last word

             % vi !70:$            (it will recall from history line 70. Open vi with a filename that is the last argument)

           % !20;!40            (combine commands in history)

           % !!:s/cat/cp          (modify contents of previous event)

                    ^^^  ^^^

                    old   new

 

Alias

 

        Performs string substitution on the command line

         

          alias [entered command] [executed command]

 

          % alias hi ‘/usr/games/banner -w30 hi’

           % alias mydir ‘ls –la | more’

           % alias m more

           % alias head tail

           % head tmpfile

           % \head tmpfile   (will avoid substitution)

 

          Remove alias

         % unalias head

         % unalias mydir

Filename Generation

         Cshell uses a ~ as a special character for file name substitution

         %ls ~

  %cp test.c ~wmorales

 

File completion

 %set filec (in cshell will activate this option for file completion)

%cat filen (TAB) or (ESC) (ESC)  (this will complete the filename if there is no other file in directory that matches filen you have to give enough information so that file completion will be able to distinguish files that start with the same initials)

 %cat test (ctrl-d) (it will list all files that start test)

 

Variables

 While tcsh stores variable values as strings, you can work with these variables as numbers. Expressions in tcsh can use arithmetic, logical, and conditional operators. The @ builtin can also evaluate arithmetic expressions.

 A tcsh valiable consists of 1 to 30 characters that can be letters, digits and underscore. The first character has to be a letter.

 Commands that declare and manipulate variables:

set- assumes that a variable is non-number string var

@ - only works with numeric variables

setenv – declares a variable and places it in the calling environment of all child processes

 % set name = walter

 % echo $name

 % set  (shows all the variables)

 

Array of strings

 % set weekday = (Monday Tuesday Wednesday Thursday Friday)

 % echo $weekday

 % echo $weekly[1-3]

 % set months = (‘ ‘   ‘ ‘   ‘ ‘   ‘ ‘   ‘ ‘   ‘ ‘)  (it creates an empty array to hold 6 items)

 % echo $months

 % set months[2]=February

 

Numeric variables

 % @ count = 0

 % echo $count

 % @ count = ( 5 + 2 )

 % echo $count

 % @ result = ( $count  <  5 )

 % echo $result

 % @ count  +=  5

 % @ count++

 % echo $count

  

Arrays of numeric values

 % set ages = (0 0 0 0 0)

 % @ ages[2] = 15

 % @ ages[3] = ($ages[2] + 4)

 % echo $ages[3] 

% echo $ages

 

 Special forms of user variables

 %echo $#varname (shows the numbers of elements in the array varname)

 %echo $?varname (verify if a variable is declares 1=true)

  

Braces { }

 If you want to distinguish a variable from surrounding text  

 

 %echo $prefix{ander} is the full name

 

 

 

horizontal rule

Back to CS140U Homepage
This page was last modified September 26, 2004
wmorales@pcc.edu