next up previous contents
Next: Multiple Commands Per Line Up: The Bourne Shell Previous: A Bit of History

Getting to Know the Bourne Shell

If the user sits down and starts typing a few Unix commands he will be utilizing the shell that happens to be installed. A good place to start is to confirm that the resident shell is, in this case, the Bourne shell. To check if this is true, type the following command:

echo $SHELL

and the output should be

/bin/sh

indicating that the shell being used is indeed the Bourne shell.

If this is not the case, and another shell is installed, the chsh command can be used to change the shell, or for the purpose of learning the shell, an interactive shell can be invoked using the sh command. While the default prompt for a non-root user in the Bourne shell is a $, this is not really a good way to determine the current active shell since in any shell the prompt can be changed. For the rest of the examples in this section a dollar sign will lead the text to emulate the prompt.

Now that the current working shell is a Bourne shell, it can be examined in some detail. It is instructional to look at what exactly happens when a command is entered. The user types in any command on a line followed by the enter-key or return-key, for example,

$ cp *.txt text_files <enter>

This is a common enough command, it moves all of the files with a .txt extension from the current working directory to a subdirectory called text_files. The shell is set into action by the enter-key. It begins immediately by searching the Unix command for anything foreign to the command. For example it looks for variables, pipelines, other redirection characters and command separators - all of which will be covered in due time. The above example contains nothing but a simple Unix command so the shell passes the command to the operating system which then processes it. If any of the special characters mentioned above had been contained in the command, the shell would have handled them before passing the command off to the operating system. What if the command was too long for the terminal window? No problem. The input may look different to different users since some terminals will wrap longer commands onto the next line, and others will adjust in such a way that the command will keep going to the right past the terminal boundary. In either case, the shell waits until the enter-key has been pressed before taking any action. There is a way however to enter a long command such that it will be broken at the end of the top line and continued on the next. This can be accomplished by typing a backslash (\) character before pressing return at the breakpoint, as follows:

$ echo This is a long command so why not break it here \
> and start on the next line. <enter>

which gives as output:

This is a long command so why not break it here and start on the next line.

The > is the shell's way of letting the user know that the current line is a continuation of the previous line. Note however that the output is printed as though it was never broken.


next up previous contents
Next: Multiple Commands Per Line Up: The Bourne Shell Previous: A Bit of History

Douglas M Gingrich
Mon Apr 27 15:25:49 MDT 1998