Previous Table of Contents Next


CHAPTER 8
Understanding Shells

Commands Common to All Shells
The Bourne Shell
The C Shell
The Korn Shell

THE SOLARIS 2.X ENVIRONMENT PROVIDES THREE SHELLS FOR USE AS COMMAND interpreters the Bourne shell (the default), the C shell, and the Korn shell. One shell is defined as the default shell for each user, but users can start a new shell from any command line. This chapter describes elements that are common to all three shells and then provides a section for each shell that describes some of the prevalent shell features.

Table 8-1 lists the basic shell features and shows which shells provide each feature.

Table 8-1 Basic Features of Bourne, C, and Korn Shells

Feature Bourne C Korn
Aliases No Yes Yes
Command-line editing No Yes Yes
Enhanced cd No Yes Yes
History list No Yes Yes
Ignore CTRL-D (ignoreeof) No Yes Yes
Initialization file separate from .profile No Yes Yes
Job control Yes Yes Yes
Logout file No Yes No
Protect files from overwriting (noclobber) No Yes Yes
Syntax compatible with Bourne shell Yes No Yes

Commands Common to All Shells

The following sections describe commands that can be used with any shell.

Setting a Default Shell

The user's login shell is set in the last field of the user's entry in the Passwd database or /etc/passwd file. Use Solstice AdminSuite's User Manager to edit the Passwd database. Use Admintool: Users to edit the local /etc/passwd file. To run Admintool on a local system, you must be a member of the sysadmin group (GID 14):

1.  Type admintool& and press Return to start Admintool (if necessary).
2.  Click on the user account you want to change. The user account is highlighted.
3.  From the Edit menu, choose Modify. The Admintool: Modify User window is displayed.
4.  Choose the new login shell from the Login Shell menu.
5.  Click on the OK button. The next time the user logs out and logs in again, the new shell is used.

Changing Shells from a Command Line (csh, ksh, sh)

If you want to use another shell without modifying the Passwd database, you can change shells at a command line prompt by simply typing the name of the shell you want to use.

To change to the C shell, type csh and press Return. The default C shell prompt is the system name followed by a percent sign (%):

$ csh
oak%

To change to the Korn shell, type ksh and press Return. The default Korn shell prompt is a dollar sign ($):

oak% ksh
$

To change to the Bourne shell, type sh and press Return. The Bourne shell prompt also is a dollar sign ($):

$ sh
$

Quitting from a Shell (exit)

If you start a new shell from the command line, you can quit it and return to the old shell. To quit from a shell, type exit and press Return. If you have started (layered) another shell, you are returned to the original shell prompt:

$ exit
oak%

Clearing a Shell Window (clear)

You can clear the contents of a shell window and redisplay the prompt to the top of the window. To clear the contents of a shell window, type clear and press Return:

oak% which openwin
no openwin in . /home/ignatz /usr/deskset/bin /usr/bin

/home/ignatz/bin /bin /home/bin /etc /usr/etc /usr/ucb

oak% clear

The window is cleared and the prompt is redisplayed at the top.

The Bourne Shell

The default shell for the Solaris 2.x environment is the Bourne shell, developed by Steve Bourne when he was at AT&T Bell Laboratories. The Bourne shell is a small shell for general-purpose use. It also provides a full-scale programming language that is used to develop shell scripts to capture frequently performed commands and procedures. Describing how to write shell scripts is beyond the scope of this book.

Reviewing the Bourne Shell Initialization File

The Bourne shell uses one initialization file, .profile, in the user's home directory to set the user's environment. When the user logs in or starts a Bourne shell from the command line, the .profile file is read. Use this file to set the user's path and any environment variables.

Defining Bourne Shell Environment Variables

The syntax for defining an environment variable is the same for both the Bourne and Korn shells; type VARIABLE=value;export VARIABLE and press Return.

$ PS1=oak$;export PS1
$

The C Shell

The C shell, written by Bill Joy when he was at UC-Berkeley, is popular with many users of Berkeley UNIX. The C shell is completely different from the Bourne and Korn shells and has its own syntax. The most important advantages of the C shell are command history, command editing, and aliases. Command history stores a record of the most recent commands that you have used. You can display these commands and reuse them as originally issued. You can also change a command by editing it. Aliases let you type short names for frequently used commands. You can also combine sequences of frequently used commands and provide an alias for the sequence.

Reviewing C Shell Initialization Files

The C shell uses two initialization files in the user's home directory to set the user's environment: .login and .cshrc (C shell run control).

When the user logs in, the .login file is read, and then the .cshrc file. When you start the C shell from a command line, only the .cshrc file is read. Because the .login file is not always read, you should set environment variables and the user's path in the .cshrc file.

Defining C Shell Environment Variables

To define an environment variable for the C shell, type setenv VARIABLE value and press Return:

oak% setenv DISPLAY rogue:Ø
oak%


Previous Table of Contents Next