Flylib.com

Books Software

 
 
 

Objectives


[Page 295 ( continued )]

Objectives

In this chapter, I explain and demonstrate the C-shell-specific facilities.



[Page 295 ( continued )]

Presentation

The information in this section is presented in the form of several sample Linux command sessions and a small project.



[Page 296]

Shell Commands

This section introduces the following shell commands, listed in alphabetical order:

alias

chdir

dirs

foreach..end

glob

goto

history

if..then..else..endif

logout

nice

nohup

notify

onintr

popd

pushd

rehash

repeat

set

setenv

source

stop

suspend

switch..case..endsw

unalias

unhash

while..end



[Page 296 ( continued )]

8.1. Introduction

The C shell is available on Linux as /bin/tcsh, and is completely compatible with the UNIX C shell with some enhancements of its own. A link from /bin/csh to /bin/tcsh is provided, so UNIX users can reference it as csh .

The C shell supports all of the core shell facilities described in Chapter 5, "The Linux Shells," plus the following new features:

  • several ways to set and access variables

  • a built-in programming language that supports conditional branching, looping, and interrupt handling

  • command customization using aliases

  • access to previous commands via a history mechanism

  • advanced job control

  • filename completion and command editing



[Page 296 ( continued )]

8.2. Startup

The C shell is a regular C program whose executable file is stored as "/bin/tcsh". If your chosen shell is "/bin/tcsh", an interactive C shell is invoked automatically when you log into a Linux system. You may also invoke a C shell manually from a script or from a terminal by using the command tcsh. tcsh has several command-line options that are described at the end of this chapter.

When a C shell is started as a login shell, a global login initialization file, "/etc/login" may also be executed. This is useful for setting up environment variables (such as PATH ) to contain information about the local environment.

When a C shell is invoked, the startup sequence is different for login shells and nonlogin shells (Figure 8-1).


[Page 297]
Figure 8-1. C shell startup sequence.

Step

Shell type

Action

1

both

Execute commands in $HOME/.tcshrc or $HOME/. cshrc if it exists.

2

login only

Execute commands in global login initialization file if it exists.

3

login only

Execute commands in $HOME/.login if it exists.


Note that the ".tcshrc" (or if not found, ".cshrc") file is run before either type of login initialization file. This may seem counterintuitive and has been the cause of much unexpected behavior when users are crafting their initialization files. The way to keep this straight is to remember that the C shell always runs its own initialization file immediately upon starting, then determines if the shell is a login shell which would require running the other initialization files.

Once an interactive shell starts and finishes running all the appropriate initialization files, it displays its prompt and awaits user commands. The standard C shell prompt is %, although it may be changed by setting the local variable $prompt, described shortly.

The ".login" file typically contains commands that set environment variables such as TERM , which contains the type of your terminal, and PATH, which tells the shell where to search for executable files. Put things in your ".login" file that need to be set only once (environment variables whose values are inherited by other shells) or make sense only for an interactive session only (like specifying terminal settings). Here's an example of a ".login" file:

echo -n "Enter your terminal type (default is vt100): "
set termtype = $<
set term = vt100
if ("$termtype" != "") set term = "$termtype"
unset termtype
set path=(. /bin /usr/bin /usr/local/bin )
stty erase "^?" kill "^U" intr "^C" eof "^D" crt crterase
set cdpath = (~)
set history = 40
set notify
set prompt = "! % "
set savehist = 32


The ".tcshrc" file generally contains commands that set common aliases (discussed later) or anything else that only applies to the current shell. The "rc" suffix stands for " r un c ommands." Here's an example of a ".tcshrc" file:

alias h history
alias ll ls -l
alias ls ls -F
alias rm rm -i
alias m more