The UNIX shell is a program that accepts commands from a user and executes them. The shell effectively surrounds the UNIX kernel, which is a special program having exclusive access to the computer hardware (memory, processor, disks, etc.) which other programs need to run.
Several UNIX shells are available here at USC including:
sh |
Bourne Shell |
csh |
C Shell |
tcsh |
T Shell |
ksh |
Korn Shell |
bash |
Bourne-Again Shell |
All new ITS UNIX accounts are set up with tcsh as the default shell. To see what shell you currently have running, type:
echo $shell
To see your default shell, type:
finger <your_username>
and look at your shell variable. You can change your default shell at any time by typing chsh
at the UNIX prompt.
Each shell sources a different configuration file when it is invoked. These are the corresponding configuration files:
sh |
.profile |
csh |
.cshrc |
tcsh |
.tcshrc or .cshrc |
ksh |
.profile |
bash |
.bash_profile, .bash_login or .profile |
You can invoke a shell at anytime by typing the shell name at the UNIX prompt. For example, you could type
tcsh
to start a T shell. You must type exit
to close the
current shell and return to the previous shell.
For more information on any of the above shells, type:
man
<shell>
For example:
man csh
ITS Consulting Supports supports only csh and tcsh. The following are some useful features of csh and/or tcsh.
History Mechanism (csh & tcsh)
By default, both shells keep track of the last 25 commands you have typed in. To see the last 25 commands you have typed in, type history
.
You can execute previous commands without retyping them by typing:
!!
or
!<#>
Example:
!14
which will execute the command numbered 14.
You may also use:
!
<string>Example:
!man
which will execute the last command starting with man
.
If you want your shell to remember more than your last 25 commands, add the following command to your .cshrc
or .tcshrc
file:
set history
=<#>Example:
set history=50
If you want your shell to remember your commands after you logout, you can modify your .cshrc
file so that the next time you login, those commands will appear in your history list.
Add the following command to your .cshrc
or .tcshrc
file:
set savehist
=<#>Example:
set savehist=25
Note: make sure the value of your savehist
variable is less than the
value of your history
variable.
When savehist
is set, your history list is saved into a file called .history
when you logout. The next time you login, your .history
file is read back into your history list.
Command Line Editing (tcsh)
If you use tcsh, you can edit the command line using the arrow keys and emacs key strokes. Type man tcsh
for more information. Some common emacs keystrokes are:
^P
previous command
^N
next command
^F
move the cursor forward
^B
move the cursor backward
^U
delete the entire line
^Y
undelete the entire line
^D
delete the current character
^A
go to the beginning of the line
^E
go to the end of the line
Filename Completion (csh & tcsh)
For csh, if you type in a partial filename and type the Esc
key, one of two things will
happen. If the partial filename is unambiguous, the shell will fill in the remaining characters of the matching filename from the current directory.
If the partial filename is ambiguous, the shell will beep at you to indicate that either no file starts with the partial
filename, or more than one file starts with the partial filename. To list all the possible filename completions, type in a
partial filename and then type <Control>-d
.
For tcsh, if you type in a partial file, directory, command or variable name and hit the Tab
key, one of two things will happen. If the partial name is unambiguous, the shell will fill in the remaining characters of the matching file, directory, command or variable. If the partial name is ambiguous, the shell will beep to indicate that either no file, directory, command or variable starts with the partial name or more than one file, directory, command or variable starts with the partial name. To list all the possible file, directory, command or variable completions, type in a partial name and then type <Control>-d
.
With tcsh, you can also use wildcards in a file, directory or command name and then request a list of all possible completions by typing <Control>-x g
. For example:
ls prog*.c^Xg
With tcsh, you can also complete the expansion by typing <Control>-x *
.
For example, if you type:
ls *.c^X*
Your command line will be expanded to all the filenames that end in .c for example:
ls prog1.c prog2.c prog3.c
You can then edit the command or type <Return>
to execute the command.
Spelling Correction (tcsh)
With tcsh, you can correct the spelling of a filename. If you type in an incorrect filename on the command line and type <Esc> s
before you type <return>
, tcsh will
correct the misspelled filename. For example, if you had a file named assignment
, but you
accidentally typed:
ls assingment
Instead of backing up and retyping the word, you can type <Esc> s
and the shell will
attempt to correct the filename by matching it against all the files in the current directory.
You can also have tcsh correct mispelled command or variable names by putting the following command in your .tcshrc
or .cshrc
file:
set correct=all
Then, if you mispelled enscript, instead of backing up and retyping the command, you could type:
ensript<Esc> s
Changing the Default Prompt (csh & tcsh)
You can change the default prompt for csh and tcsh by putting the following command in your .cshrc
or .tcshrc
file:
set prompt =
"<whatever you want your prompt to be>"
For example:
set prompt = "Hello, Dave."
For tcsh, you can also use variables in your prompt. Some example variables are:
%c
current working directory
%m
host
%t
time
%h
history
So if you type something like:
set prompt = "%m %c %t (%h): "
Your prompt will look something like:
aludra ~ 10:53am (1):
You can also use underline, bold or reverse text portions of your prompt by surrounding them with variables such as:
%U
<text>%u
<text> will be underlined
%B
<text>%b
<text> will be bolded
%S
<text>%s
<text> will be in reverse text
So if you type a command like:
set prompt = "%S%m%s%B%c%b%U%t%u(%h):"
You prompt will look like:
-
aludra current_dir 10:58a (2):
where aludra is in reverse, the current working directory is in bold, and the time is underlined.