7.1. Introduction

 <  Day Day Up  >  

When you are at the command line you are using the shell interactively. The shell has a special built-in variable that contains a string of options. If one of the options is the letter i , the shell is running interactively. To test this, type in the following small script at the prompt:

 case "$-" in *i*) echo This shell is interactive ;; *) echo This shell is not interactive ;; esac 

The Bourne shell offers you many features to make life easier when you are working at the command line. Although the Bourne shell isn't as robust in this area as the other shells discussed in this book, it provides filename expansion, I/O redirection, command substitution, functions, and a host of other features. Once you have become familiar with the interactive shell, you will be ready to start using these features in shell scripts.

If the Bourne shell is your login shell, it follows a chain of processes before you see a shell prompt (see Figure 7.1).

Figure 7.1. Starting the Bourne shell.


Here's a very rough sketch of what goes on: The first process to run is called init , PID 1. It gets instructions from a file called inittab (System V), or it spawns a getty process (BSD). These processes open up the terminal ports, providing a place where standard input comes from and a place where standard output and error go, and they put a login prompt on your screen. The /bin/login program is then executed. The login program prompts for a password, encrypts and verifies the password, sets up an initial environment, and starts up the login shell, /bin/sh , the last entry in the passwd file. The sh process looks for the system file, /etc/profile , and executes its commands. It then looks in the user 's home directory for an initialization file called .profile . After executing commands from .profile , the default dollar sign ( $ ) prompt appears on your screen and the Bourne shell awaits commands. Of course, most systems today start up with a graphical user interface that provides a login window, a virtual desktop, and submenus to start up shell terminals and other applications. This is more a more complex setup than shown in Figure 7.1, but once the user selects a terminal window, a prompt will appear, and the shell will wait for commands.

 <  Day Day Up  >  


UNIX Shells by Example
UNIX Shells by Example (4th Edition)
ISBN: 013147572X
EAN: 2147483647
Year: 2004
Pages: 454
Authors: Ellie Quigley

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net