Chapter 3. General Unix

Table of Contents

Shells
What is a shell?
What is an environment variable?
How do I set an environment variable?
What files does (t)csh read when it starts?
How do I set my path with (t)csh?
What is a cooler way to set my path with tcsh?
How do I add a directory to my path?
File Permissions
What are file permissions?
How do I change file permissions?
The X Window System
What is X?
How do I start X?
What files get read when I run startx?

Shells

What is a shell?

A shell is the program that takes what you type at the keyboard and interprets, then eventually executes a command. A shell can do a number of things to make your environment easier, such as doing command line completion, performing substitutions, allowing you to set variables and more.

What is an environment variable?

An environment variable is a shell variable that gets inherited by all of the processes spawned by the shell that first set it. For instance, if I set the environment variable FOO, and then ran the program make, make would then have access to the variable FOO that I had set.

How do I set an environment variable?

How to set an environment variable depends on which shell you are running. (t)csh sets an environment variable with the following syntax:

setenv VARIABLE value

With bourne and POSIX shells (such as sh, bash, zsh, ksh), you set an environment variable like this:

VARIABLE=value ; export VARIABLE

What files does (t)csh read when it starts?

csh and tcsh read a number of files when they startup. You can put things in these files and they will be sourced when you login.

Here is a list of the files these shells read when they startup. The list is in the order in which the files are read(to the best of my knowledge):

  1. /etc/csh.cshrc

  2. Sources /usr/share/init/tcsh/rc

  3. /etc/csh.login

  4. Sources /usr/share/init/tcsh/login

  5. $HOME/.cshrc

  6. $HOME/.tcshrc (tcsh only, and only if .cshrc doesn't exist)

  7. $HOME/.login

And when you logout, it reads:

  1. /etc/csh.logout

  2. Sources /usr/share/init/tcsh/logout

  3. $HOME/.logout

Under Darwin, the global default files in /etc actually source files in /usr/share/init/tcsh

How do I set my path with (t)csh?

You should edit your $HOME/.cshrc file to set your path every time you login. The simple way to set your path is to add a line like this to your .cshrc file:

set path=(/bin /usr/bin /sbin /usr/sbin /usr/local/bin /usr/local/sbin)

The directories listed within the parentheses will then be included in your path, and you can execute any program within those directories. Be careful what order you put the directories in. If a program has the same name, in different places, the first one to appear in your path will be the one used. So, if you had /bin/ls and /usr/local/bin/ls, with the path above when you type ls, /bin/ls will be executed.

What is a cooler way to set my path with tcsh?

If you want to make sure only directories that exist are in your path, you can use something like this:

set p=()
foreach x ( /directory /list )
  if (-d $x) set p=( $p $x )
end
set path = ( $p )
unset p

This will try every directory listed in the ( /directory /list ) section, and if that directory exists on your system, it will be added to your path.

How do I add a directory to my path?

If you use (t)csh and you have setup your path as I recommend in the above section, then you should just add the new directory to your .cshrc file.

If you just want to add a directory to your path on the command line, with (t)csh, you can use:

set path = ( $path /tmp )

With a Bourne shell syntax you can use:

PATH="$PATH:/tmp"; export PATH

These will both add /tmp to the end of your path.