Setting up your Unix environment

Most of the Unix interaction in the lab will be on the command line. Graphical desktops exist for Unix, including GNOME and KDE on top of X11, and MacOS X, where the Unix underpinnings are thoroughly hidden most of the time.

There are two command shells that you are going to encounter on our systems. On the Macs you will be using the Bourne Shell (sh or more likely its successor bash or Bourne Again Shell) unless you change your shell, and on the Linux systems in CS you will be using the C Shell (csh or more likely its successor tcsh or Tenex C Shell). For most day to day use they are functionally equivalent. However they have very different scripting languages and ways of setting up the environment. The main concept that we need to worry about for setting up the environment is how to set environmental variables.


1. Bash

The Bourne Shell was originally written by Stephen Bourne at AT&T Bell Labs in the mid-to-late 1970s. Most systems now use Bash, which is an extended replacement written by the Free Software Foundation for the GNU project.

1.1. .bash_profile

At login the system automatically runs a file in your home directory called .bash_profile to set up the environment. You will need to edit this file to be able to use some third party software installed on the Macs. If you choose to change your shell on the CS Linux machines to Bash, you'll have to convert the C Shell settings given in later in this page to Bash syntax. Below are some shell commands you'll need to know and then some settings you'll want to change.

1.1.1. comments

Anything after a # is a comment. This is useful for documenting why you are doing something or to temporarily prevent the evaluation of a line of the file.

1.1.2. export

Unlike the C Shell, which makes a distinction between shell variables and environment variables, Bash sets them both the same way: with the export command.

1.1.3. Changes you need to make

Set the following environmental variables if you work with the TGrep2 corpus search tool:

HLP="/p/hlp"
export HLP

TGREP2ABLE="$HLP/corpora/TGrep2able"
export TGREP2ABLE

TGREP2_CORPUS="$TGREP2ABLE/swbd.t2c.gz"
export TGREP2_CORPUS

TDT="/p/hlp/tools/TDT"
export TDT

TDT_DATABASES="$TDT/databases"
export TDT_DATABASES

SWBD_XML_DATABASES="/p/hlp/corpora/p-swbd/SWBD-xml-2-15-08/PAGE/Data/xml/"
export SWBD_XML_DATABASES

The following lines change your path so you can use Python (2.4.4 instead of the default 2.3.5), LaTex, Tcl/Tk, SBCL Common Lisp, ImageMagick, and Subversion:

PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}:/usr/local/bin:/usr/texbin:/p/hlp/bin"
export PATH

1.1.4. Optional changes

You may or may not like the default command prompt that Apple uses. Luckily the prompt can be changed. The following is a nice prompt:

PS1="\u@\h:\w\$ "
export PS1

This shows your username @ computer name : working directory $

If you want to have colors in Terminal.app, add the following line:

export CLICOLOR=1


2. C Shell

The C Shell was originally written by Bill Joy at UC Berkeley in the mid-1970s. (This should sound familiar if you've read the Vi(m) page.) It was given the name because the syntax of its scripting language is designed to be similar to the C programming language. Almost all modern systems (including the CS system here at Rochester) actually use the Tenex C Shell, which is a heavily extended rewrite of the original.

2.1. .cshrc

At login the system automatically runs a file in your home directory called .cshrc to set up the environment. You will need to edit this file to be able to use the corpus tools. Below are some shell commands you'll need to know and then some settings you'll want to change.

2.1.1. comments

Anything after a # is a comment. This is useful for documenting why you are doing something or to temporarily prevent the evaluation of a line of the file.

2.1.2. set and unset

set and unset are used to manage built-in shell variables.

2.1.3. setenv and unsetenv

setenv and unsetenv are used to manage environment variables.

2.1.4. alias and unalias

alias and unalias are used to alias commands to other commands.

2.1.5. Changes you need to make

Somewhere near the top of the file, but after the

# Do Not Remove This
source /usr/staff/lib/defaults/system.cshrc

lines, add the following lines for environment variables related to the corpus tools:

# Corpus related variables
setenv HLP /p/hlp
setenv NLP /p/nl
setenv TOOLS $HLP/tools
setenv TDT $TOOLS/TDT
setenv TDT_DATABASES $TDT/databases
setenv TGREP2ABLE $HLP/corpora/TGrep2able
setenv TGREP2_CORPUS $TGREP2ABLE/brown.t2c.gz

On the last line with TGREP2_CORPUS set the value of the part after the final forward slash to one of the corpora in the /p/hlp/corpora/TGrep2able/ directory. For this example I've used the Brown corpus.

We also need to change our path to add the directory with the corpus tools. This needs to come somewhere after the corpus related variables we just set, as it references one of them.

# PATH addition
set path = ($path $home/bin $HLP/bin)

2.1.6. Optional changes

Near the bottom of the CS provided .cshrc there is a section that starts with the comment

# add all INTERACTIVE commands here, specifically, any stty or prompt setting

In between the if and endif following that, you can set some nice optional settings.

You may or may not like the default command prompt that the CS environment uses. Luckily the prompt can be changed. The following sets a nice prompt:

set promptchars = "%#"
set prompt = "%n@%m:%~ %# "

This shows your username @ computer name : working directory % (if normal user) | # (if superuser)

If you worry about accidentally deleting files, add the following to have the system ask permission before deleting each file:

alias rm 'rm -i'

If this gets annoying you can always type unalias rm at the command line to turn off interactive mode for rm until you logout.

If you don't want to be accidentally logged out if you hit ^D (aka EOF or "end of file"):

set ignoreeof

If you don't want it to be possible to overwrite a file through output redirection:

set noclobber

HlpLab: UnixEnvironment (last edited 2011-08-10 17:28:48 by AndrewWatts)

MoinMoin Appliance - Powered by TurnKey Linux