What is C Shell (and Tcsh) in UNIX/Linux System

Linux TLDR
Last Updated:
Reading time: 3 minutes

The C shell (or CSH) is one of the earliest UNIX/Linux shell interpreters, developed by Bill Joy at the University of California, Berkeley, in the late 1970s, inspired by the C programming language.

Along with Bash and Korn Shell, these three were the most popular shell interpreters in the early 1990s and distributed as the default login shell in most UNIX/Linux systems.

On systems like macOS or Red Hat, instead of C shell, you will find its extended version, Tcsh (also known as β€œtee-see-shell” or β€œtee-shellβ€œ), as a symbolic link pointing towards its original source.

The β€œt” in β€œtcsh” comes from the β€œT” in the TENEX operating system, and many features were taken from this OS as inspiration by the author of Tcsh while studying at Carnegie Mellon University.

The Tcsh added features are enhanced history substitution (which allows you to execute previously entered commands using the β€œβ†‘β€ and β€œβ†“β€ keys), spelling correction, and word completion (press the tab button to autocomplete).

Significant Features

The following is a list of known features:

  • History substitutions
  • Job control facilities
  • Interactive filename and command completion
  • Support C-like syntax
  • Support shell script execution
  • Backward compatible with the C shell

While Tcsh was popular way back in time, it lost its popularity as it stepped backward. Even today, you will rarely find any UNIX/Linux system with Tcsh as the default login shell, except for BSD systems.

Even if you want to give it a try, I recommend you go with Tcsh (instead of C Shell).

How to Install Tcsh in Linux

By default, Tcsh is included in most Linux repositories and can be easily installed using the default package manager.

To install it, execute one of the following commands based on your system type:

$ sudo apt install tcsh                                                                                    #On Debian and Ubuntu
$ sudo dnf install tcsh                                                                                    #On Fedora and RHEL
$ sudo pacman -S tcsh                                                                                  #On Arch and Manjaro

After the installation is complete, execute the following command to verify its existence:

$ which tcsh

#OR

$ tcsh --version

Output:

Verifying the Tcsh installation

You can enter in interpreter mode by executing the tcsh command; however, execute the following chsh command if you want to have it as your default shell:

$ chsh -s $(which tcsh)

Output:

Changing the default shell to tcsh

After the above command is executed, logout from your system to reflect the changes, and then execute the following command to verify your default shell:

$ echo $0

Output:

Verifying the existing shell

You can also notice the default β€œ$” representing the Bash interpreter is replaced with β€œ>” in Tcsh.

A Few Differences Between the Tcsh and Bash

If you were a Bash user and switched to Tcsh for a short or long time, then you would find the following differences between them:

Setting Shell Variables

In Bash, you can directly specify the variable name (or key) to initialize; however, Tcsh requires the set keyword before the variable name (or key) while initializing.

> set var1=testing
> echo $var1

Output:

Setting variables in Tcsh

Creating Environment Variables

The export command used in Bash to create an environment variable does not work in Tcsh; instead, you need to use the setenv command and specify the variable in β€œKEY VALUE” format without using the equals sign, as shown.

> setenv var1 testing
> printenv var1

Output:

Setting environment variables in Tcsh

Adding Directory to the $PATH Variable

The $PATH variable stores the list of directories used to look for binary or program files that are executed from your terminal.

Tcsh also uses the same variable for searching binaries and programs; however, adding a path to this variable is different from Bash, as shown.

> set path = ($path $HOME/script/)
> echo $PATH

The above command will add the β€œ/home/linuxtldr/script” path to the $PATH variable.

Adding path to the $PATH variable

Creating Aliases in Tcsh

Creating aliases in Tcsh is identical to Bash, except you have to avoid using the equals sign.

> alias www "cd /var/www/html"
> alias www

Output:

Creating an alias in Tcsh

Tcsh Configuration Files

The Tcsh utilizes different configuration files for login and non-login shells instead of Bash, as shown.

  • For login shell: β€œ/etc/csh.cshrcβ€œ, β€œ/etc/csh.loginβ€œ, β€œ~/.tcshrcβ€œ, β€œ~/.cshrcβ€œ, and β€œ~/.loginβ€œ.
  • For non-login shell: β€œ/etc/csh.cshrcβ€œ, β€œ~/.tcshrcβ€œ, and β€œ~/.cshrcβ€œ.
  • Logout clean up: β€œ/etc/csh.logout” or β€œ~/.logoutβ€œ.

That’s all the difference as a beginner you should know about Tcsh.

How to Remove Tcsh in Linux

If you are bored with Tcsh and want to remove it immediately from your system, then execute the following command to change back to your previous shell (ex: bash):

> chsh -s /bin/bash

Output:

Changing back to the previous shell

After executing the above command, log out and log back in to your system to reflect the changes, then execute the following command to verify your existing shell:

$ echo $0

Output:

Checking the existing shell

Lastly, execute any one of the following commands to remove Tcsh from your Linux system:

$ sudo apt remove tcsh                                                                                    #On Debian and Ubuntu
$ sudo dnf remove tcsh                                                                                    #On Fedora and RHEL
$ sudo pacman -R tcsh                                                                                     #On Arch and Manjaro

That’s all you need to do to remove Tcsh from your Linux system.

We will end the article here, but if you want me to write more articles related to this topic, let me know in the comment section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.