-->
Previous Table of Contents Next


Job Control

Job control refers to the ability to control the execution behavior of a currently running process. Specifically, you can suspend a running process and cause it to resume running at a later time. tcsh keeps track of all the processes that it starts as a result of user input. You can suspend a running process or restart a suspended one at any time during the life of that process.

Pressing the Ctrl+Z key sequence suspends a running process. The bg command restarts a suspended process in the background, and the fg command restarts a process in the foreground.

These commands are most often used when you want to run a command in the background but accidentally start it in the foreground. When a command is started in the foreground, it locks the shell from any further user interaction until the command completes execution. This is usually not a problem because most commands take only a few seconds to execute. If the command you’re running is going to take a long time, you will probably want to start the command in the background so that you can continue to use tcsh to enter other commands.

For example, if you start a command that is going to take a long time in the foreground, such as


find / -named “test” > find.out

your shell will be tied up for several minutes. If you have done this and want to cause the find command to continue executing in the background, you can enter the following:


Ctrl-z

bg

This suspends the find command and then restarts it in the background. The find command continues to execute, and you regain control of tcsh.

Key Bindings

Like the pdksh, tcsh provides the ability to change and add key bindings. The tcsh implementation of key bindings is more powerful than the way key bindings are done in pdksh.

With tcsh you can bind to things other than the built-in editor commands. This means that you can bind a key to a UNIX command, for example. tcsh also enables you to bind vi editing commands, whereas pdksh only allows the binding of emacs editing commands.

Key bindings can be very useful, especially if you’re using a favorite editor other than emacs or vi. The basic syntax for defining key bindings is


bindkey [option] <instring or keyname> <outstring or command>

The options that bindkey supports are not discussed in this book. If you want to learn about the bindkey options, refer to the tcsh man page. The basic function of the bindkey command is to bind the key sequence contained in the first argument to the command contained in the second argument.

The following list gives some of the most useful editing commands that you can bind key sequences to, along with the default key binding for that command. You can list all the bindings that are defined in tcsh by typing the bindkey command without any arguments.

  beginning-of-line (^A): Moves the cursor to the beginning of the command line.
  backward-char (^B): Moves the cursor back one character.
  end-of-line (^E): Moves the cursor to the end of the command line.
  forward-char (^F): Moves the cursor forward one character.
  backward-delete-char (^H): Deletes the character to the left of the cursor.
  kill-line (^K): Deletes all of the characters to the right of the cursor.
  clear-screen (^L): Removes all of the text from the shell window.
  down-history (^N): Moves down one command in the history list.
  up-history (^P): Moves up one command in the history list.
  kill-whole-line (^U): Deletes all of the characters on the current line.

All of these commands are the same whether you’re in emacs or vi insert mode. tcsh supports many more editing commands than are listed here. To see what these commands are, refer to the tcsh man page.

The following are examples of setting key bindings:


bindkey ^W kill-whole-line

bindkey ^S beginning-of-line

Other Neat Stuff

tcsh supports several neat features that none of the other shells discussed in this book supports. This section lists a few of the most useful of these extended features.


Previous Table of Contents Next