9. Your Working Environment
Prev |  | Next

## 9. Your Working Environment

Your shell is the most important part of your working environment. In DOS, the usual shell is command.com. The shell is what interprets the commands you type on the command line, and thus communicates with the rest of the operating system. You can also write shell scripts, which are like DOS batch files: a series of commands to be run without your intervention.

Two shells come installed with FreeBSD: `csh` and `sh`. `csh` is good for command-line work, but scripts should be written with `sh` (or `bash`). You can find out what shell you have by typing `echo $SHELL`.

The `csh` shell is okay, but `tcsh` does everything `csh` does and more. It allows you to recall commands with the arrow keys and edit them. It has tab-key completion of filenames (`csh` uses the Esc key), and it lets you switch to the directory you were last in with `cd -`. It is also much easier to alter your prompt with `tcsh`. It makes life a lot easier.

Here are the three steps for installing a new shell:

1. Install the shell as a port or a package, just as you would any other port or package. Use `rehash` and `which tcsh` (assuming you are installing `tcsh`) to make sure it got installed.

2. As `root`, edit `/etc/shells`, adding a line in the file for the new shell, in this case `/usr/local/bin/tcsh`, and save the file. (Some ports may do this for you.)

3. Use the `chsh` command to change your shell to `tcsh` permanently, or type `tcsh` at the prompt to change your shell without logging in again.

### Note:

It can be dangerous to change `root`'s shell to something other than `sh` or `csh` on early versions of FreeBSD and many other versions of UNIX®; you may not have a working shell when the system puts you into single user mode. The solution is to use `su -m` to become `root`, which will give you the `tcsh` as `root`, because the shell is part of the environment. You can make this permanent by adding it to your `.tcshrc` file as an alias with:

alias su su -m

When `tcsh` starts up, it will read the `/etc/csh.cshrc` and `/etc/csh.login` files, as does `csh`. It will also read the `.login` file in your home directory and the `.cshrc` file as well, unless you provide a `.tcshrc` file. This you can do by simply copying `.cshrc` to `.tcshrc`.

Now that you have installed `tcsh`, you can adjust your prompt. You can find the details in the manual page for `tcsh`, but here is a line to put in your `.tcshrc` that will tell you how many commands you have typed, what time it is, and what directory you are in. It also produces a `>` if you are an ordinary user and a `#` if you are `root`, but tsch will do that in any case:

set prompt = "%h %t %~ %# "

This should go in the same place as the existing set prompt line if there is one, or under "if($?prompt) then" if not. Comment out the old line; you can always switch back to it if you prefer it. Do not forget the spaces and quotes. You can get the `.tcshrc` reread by typing `source .tcshrc`.

You can get a listing of other environmental variables that have been set by typing `env` at the prompt. The result will show you your default editor, pager, and terminal type, among possibly many others. A useful command if you log in from a remote location and can not run a program because the terminal is not capable is `setenv TERM vt100`.

Prev |  | Next
8. Next Steps | Home | 10. Other

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.
Send questions about this document to <freebsd-doc@FreeBSD.org>.