The Shell


When you type commands in an xterm, you are interacting with the Unix system using a program called the shell. The shell is primarily a command interpreter. It accepts your command, finds the executables corresponding to the command and runs the command for you. It also provides some features that make it easier for you to use the system. Actually, there are many different shells available for Unix. The default shell in our environment is a shell called tcsh . We'll look at some of the simple features offered by the tcsh shell.

Command and filename completion

If you have typed an unambiguous prefix of a command or filename, you can just hit the Tab key and the shell will complete the command or filename for you.
 
  • Type ls Tes and then hit Tab

  • Notice how the shell fills in the name of the directory Testdir1. If there are other files or directories that have the same prefix, the shell will beep to let you know that the prefix is ambiguous. 

    Emacs-like editing of commands and command history

    The shell lets you modify a command before you hit the "Enter" key. Typically, you would use the left and right arrow keys and the backspace key for this purpose. But the shell also allows you to use Emacs commands to edit your command line. The shell also stores a history of commands that you typed in during a session. You can move up and down this list using the up and down arrow keys, respectively. If you want to re-enter a command that you entered previously, you can use the up arrow to move up to the command and then hit Enter.
     
  • Move the mouse to the xterm and hit the up-arrow key. Note that the previous command (ls Testdir1) appears on the command line. Now press Enter. The command is executed again. 
  • Wildcard characters

    Most shells give you the capability to refer to more than one file using special characters like "*" and "?". The shell interprets the "*" character as "any sequence of zero or more characters." Thus, *.cpp would match all filenames that have any sequence of characters followed by .cpp or in other words, filenames that end with .cpp.
     
  • Enter the command: cd /class/sce/reference/unix/samples
  • Enter the command: ls 

  • You should see the following files listed: 

    dummy.txt   dummy1.cpp   dummy1.txt  dummy2.cpp   dummy2.txt
  • Now enter the command ls *.cpp 

  • Note that now only the files ending in .cpp are listed. In the command above, you're telling ls to list only those files that match your criteria i.e. files that end in .cpp

  • Now enter the command: ls dummy1* 

  • Observe that only the files starting with dummy1 are listed.

    The shell interprets the "?" character as "any one character".

  • Enter the command: ls dummy?.* 

  • In this case, the files listed are those starting with dummy, followed by any one character, followed by a . (dot), followed by any number of other characters. 

    Naming home directories

    In tcsh, you can refer to your home directory using the special character "~". Thus cd ~ is equivalent to cd. Similarly, "~smith" refers to the home directory of the user whose login name is "smith".
     
  • Enter the command: cd ~ 
  • The shell prompt

    The shell displays a prompt at which you enter your commands. The appearance of the prompt is customizable. In the default environment, the prompt consists of the absolute pathname of your current working directory, followed by a "%" sign on the next line. This makes it easy to keep track of which directory you are in at any point of time. 

     
    Previous Table of Contents Continue


    Last modified: Tue Jan 6 20:40:29 EST 1998