3.2.4 Shells and commands


Next: 3.2.5 Logging out Up: 3.2 Basic UNIX Concepts Previous: 3.2.3 Virtual consoles

 

  For most of your explorations in the world of UNIX, you’ll be talking to the system through the use of a shell. A shell is just a program which takes user input (e.g., commands which you type) and translates them into instructions. This can be compared to the COMMAND.COM program under MS-DOS, which does essentially the same thing. The shell is just one interface to UNIX. There are many possible interfaces—such as the X Window System, which lets you run commands by using the mouse and keyboard in conjunction.

As soon as you login, the system starts the shell, and you can type commands to it. Here’s a quick example. Here, Larry logs in, and is left sitting at the shell prompt.

mousehouse login: larry
Password: larry’s password Welcome to Mousehouse!

/home/larry#

  « /home/larry# » is the shell’s prompt, indicating that it’s ready to take commands. (More on what the prompt itself means later.) Let’s try telling the system to do something interesting:

/home/larry# make love make: *** No way to make target `love’. Stop.

/home/larry#

Well, as it turns out make was the name of an actual program on the system, and the shell executed this program when given the command. (Unfortunately, the system was being unfriendly.)

      This brings us to one burning question: What are commands? What happens when you type « make love »? The first word on the command line, « make », is the name of the command to be executed. Everything else on the command line is taken as arguments to this command. Examples:

READ  LinuxThreads Programming LG #48

/home/larry# cp foo bar Here, the name of the command is « cp », and the arguments are « foo » and « bar ».

When you type a command, the shell does several things. First of all, it looks at the command name, and checks to see if it is a command which is internal to the shell. (That is, a command which the shell knows how to execute itself. There are a number of these commands, and we’ll go into them later.) The shell also checks to see if the command is an alias, or substitute name, for another command. If neither of these conditions apply, the shell looks for a program, on the disk, with the command’s name. If it finds such a program, the shell runs it, giving the program the arguments specified on the command line.

In our example, the shell looks for the program called make, and runs it with the argument love. Make is a program often used to compile large programs, and it takes as arguments the name of a « target » to compile. In the case of « make love », we instructed make to compile the target love. Because make can’t find a target by this name, it fails with a humorous error message, and we are returned to the shell prompt.

    What happens if we type a command to a shell, and the shell can’t find a program with the command name to run? Well, we can try it:

/home/larry# eat dirt eat: command not found

/home/larry#

Quite simply, if the shell can’t find a program with the name given on the command line (here, « eat »), it prints an error message which should be self-explanatory. You’ll often see this error message if you mistype a command (for example, if you had typed « mkae love » instead of « make love »).

READ  Framebuffer HOWTO: Using framebuffer devices on Alpha platforms


Next: 3.2.5 Logging out Up: 3.2 Basic UNIX Concepts Previous: 3.2.3 Virtual consoles

Matt Welsh
mdw@sunsite.unc.edu