This page is about the C shell command line interpreter for FreeBSD and configuring it for use as shell. Updated 2024-02-16.

What is C shell?

The C shell in FreeBSD, known as either tcsh or csh, is a command line interpreter, also known has the shell, for Unix-like systems. The difference between tcsh and csh is, that tcsh has enhancements. on the Berkeeley UNIX C shell. FreeBSD and Unix-like systems are mostly written in the programming language C. This makes C shell a natural choice of shell. C shell’s built-in expression operators, grammar, syntax and support for arrays were all influenced by C. Read more on C shell by Wikipedia.

Changing to csh shell in FreeBSD.

The shell for a user in FreeBSD can be changed with the chsh utility. Read more on The different shells in FreeBSD by myself.

Configuring the csh shell in FreeBSD.

The csh shell in FreeBSD is configured by editing the configuration file .cshrc. This file is located in the home of each user and contains commands, that will be executed, when the shell is started, such as when the user logs into the system. In this example, the user has configured the following:

  • The command x should start the graphical user interface X and GNOME.
  • The default editor should be Nano.
  • The default paginator should be less. This is used by man and system related information.
  • The size of block units should be a kilobyte (K). Used by disk related commands, such as df, du and ls.
  • When interactive shell, then use a custom prompt, that shows current user and host in the format user@host. The short name of the host is used. Example is foobar.example.com, where foobar would be the short name. csh automatically sets the prompt, so it ends with % for a user and # for root, if %# is specified.
  • When interactive shell, execute a custom program today, that lists todays tasks. This assumes, that the path is configured in the login class capabilities database.
% nano .cshrc
alias x startx
setenv EDITOR nano
setenv PAGER less
setenv BLOCKSIZE K
if ($?prompt) then
  set prompt = "%n@%m%# "
  set promptchars = "%#"
  set filec
  set history = 1000
  set savehist = (1000 merge)
  set autolist = ambiguous
  set autoexpand
  set autorehash
  set mail = (/var/mail/$USER)
  if (-x ~/bin/today) today
endif

Distributing configuration to other users and hosts.

The configuration can be distributed to other hosts with the ssh utility.

% scp .cshrc foobar:

More about C shell.

Read more about configuring and using C shell csh in the manual csh for FreeBSD. Read more about editing MOTD on Configuring message of the day (MOTD) in FreeBSD by myself.