UC San Diego SearchMenu

Shells: Your Interface to UNIX

When you connect to a UNIX server using SSH or open a terminal from a UNIX workstation, a program called a 'shell' runs to allow you to interact with the computer.

The shell displays a prompt, often a simple '%' sign, after which you tell it what to do. The shell is not tightly bound to the inner workings of the computer, so you can choose which shell to use. The default shell on ACMS systems is the C-shell, but, in general, there are others to choose from. These other shells are described in the following section, "What are my choices?"

Shells can also be used to automate repetitive tasks using shell scripts. Programming the shell is a powerful way to get things done, and a brief overview is provided in the section entitled, "Automating Tasks Using Shell Scripts."

There is a lot of information that is beyond the scope of this article. Pointers to other sources of information are listed in the section entitled, "How To Get More Information." These sources are either on line, or highly regarded books designed with the student in mind.

What Are My Choices?

Your choice of shell is limited to those that are installed on the system you're logged into. Most ACMS systems will have most of these shells installed, but some may not. The way to check to see if your favorite shell is available is to type "cat /etc/shells" from the command prompt. This will list all the shells that have been defined, with their full pathname. Below is some information on the most common shells, in order of usability

  • TCSH

    Tcsh is an enhanced version of the C-Shell. It has all of the features of the C-Shell, with much more. Among its more advanced features: It can suggest the proper spelling for a misspelled command, you can use the up and down keys to view previously issued commands, you can use the 'tab' key to auto complete a command, and if there is more than one possible way to complete a command, it can list all the possibilities. See "man tcsh" and "man csh" information on tcsh, since the authors of the tcsh man page did not want to duplicate information. All the information found in ACMS online articles about job control and csh (by searching for 'jobs' or 'csh') also applies to Tcsh.

  • KSH

    The Korn Shell is similar to the C-shell, but has closer ties to the Bourne shell. It has the same features as the C-Shell. "man ksh" contains a very complete reference to programming with the Korn shell. It also has similar information to the "jobs" reference article.

  • CSH

    The C-Shell is the default shell on ACMS systems. It has some nice features that make it useful for interactive shells. For example, it keeps track of the commands you issued, so that you can repeat them without typing them all in. It also allows you to specify complete filenames by typing in enough characters to be specific, and pressing the escape key. Refer to "man csh" for more information about history and filename completion. The C-shell also adds job control as a feature. See the job control article for more information about making things happen in the background. There's also information on using command history under history.

  • BASH

    The Bourne-Again Shell is an attempt to add ksh and csh features to the bourne shell. It is part of the GNU project, see gnu for more information on the GNU mission. For users of emacs, bash might make more sense than the other shells. "man bash" provides a great deal of information on the shell itself.

    While the BASH is a great shell with many features, it is not fully supported for ACMS instructional use.

  • SH

    The Bourne shell (sh) is the standard command interpreter. It is a standard shell that has been around for a long time. Now, it is used primarily for shell scripts, for various reasons. Refer to "man sh" for more information.

    Since it lacks many of the features found in the other shells, it should be avoided as an everyday shell.

How Do I Change Shells?

Changing your shell is a fairly simple process.

  1. Type "cat /etc/shells" to see if your favorite shell is available, and find out where it's located. You'll need to type in the whole pathname for the command we'll run next.

    There are oftan many versions of a shell installed on a particular system. You may want to consult that shell's documentation for how to find out which version is installed in which location. For instance, to find out what version of tcsh is installed in /software/common/bin/tcsh on ieng9, I can run:

    nssgi-1 2% /software/common/bin/tcsh --version
    tcsh 6.12.00 (Astron) 2002-07-23 (mipseb-sgi-irix) options 8b,nls,dl,al,rh,color,filec
    
  2. Run chsh, the program that will change your shell. After you type "chsh", it will ask for your password, then the name of your new shell.
  3. You'll need to login again for the change to take effect.

See the man pages for these programs for more information (at the unix command prompt, type "man chsh").

How to use tcsh on systems without chsh

On some systems, either due to security or technical reasons, you might not be able to set your default shell to 'tcsh' instead of 'csh'.

If this is the case on your server, you can add a few lines to the top of your .cshrc to execute tcsh in place of csh for any shell you start.

Essentially, you need to edit your .cshrc file, and add the following lines:

     # This section will run tcsh for you...
     if (! $?tcsh && -f /usr/local/bin/tcsh) then
          echo "Running tcsh..."
          exec /usr/local/bin/tcsh $*
     endif

       

This section should be added BEFORE any other commands in the .cshrc. This is so that unnecessary commands won't run the first time- the same commands don't get executed twice.

Please note, it should only be necessary to add these lines of script if you are *unable* to change your shell to tcsh with 'chsh' or that system's equivalent. If 'chsh' or an equivalent is available, please use that to change your shell instead.

-zz1sn 4/8/98

Automating Tasks Using Shell Scripts

Shell scripts allow you to automate certain tasks. You can use them to examine printer queues, like zebras do. You can use them to automate any series of commands, and even do different things using an if statement. You can repeat statements using a for or a foreach loop.

Aliases are an alternative to shell scripts that can be used when you only want to run a one line command. You could make an alias by typing the following:

    alias rl 'rlogin'
       

That line would be typed in at the shell (normally % sign) prompt, or added into your .cshrc file. Then, you could type in 'rl ieng' to rlogin to ieng9.

Shell scripts are generally written for the Bourne shell (sh), although C shell scripts are not uncommon. As a reference for writing Bourne shell scripts, please see the man page by typing "man sh". There are many shell scripts installed on ACMS systems, so it shouldn't be hard to find examples. Your .login and .cshrc files are basic examples of C shell scripts.

Please refer to the man pages and the section of this article that describes how to get more information for recommended books.

How To Get More Information

There is a basic introduction to using the c-shell in an online article called "Files: creating, renaming, copying, redirection and pipes".

Man pages are very complete descriptions of the shell and its functions. They're free and readily available. You can type in "man csh", or replace csh with your favorite shell. If you want a hardcopy version, you can print it. The man pages for shells are rather long.

Other useful information from the Web: