The Shell

The Shell

All shells have a command prompt—the prompt usually tells the user which shell is currently being used, the user who owns the shell, and/or the current working directory. For example, the following prompt


usually indicates that the current user has superuser privileges. Shell prompts are completely customizable—the default for bash is just the name of the shell:


When you start a new terminal window from within the CDE, a shell is automatically spawned for you. This will be the same shell that is specified in your /etc/passwd entry:

apache:x:1003:10:apache user:/usr/local/apache:/usr/local/bin/bash

In this case, the apache user has the bash shell set as default. To be a valid login shell, /usr/local/bin/bash must also be included in the shells database (stored in the file /etc/shells).

If the default shell prompt is not to your liking, you can easily change its format by setting two environment variables—PS1 and PS2. Environment variables are covered in the “Setting Environment Variables” section later in this chapter, but the Solaris environment is equivalent to that found in Linux and Windows NT. For example, to set the prompt to display the username and host, you would use the following command:

PS1='\u@\H>> '; export PS1

The prompt displayed by the shell would then look like this:


Many users like to display their current username, hostname, and working directory, which can be set using the following command:

PS1='\u@\H:\w>> '; export PS1

When executed, this shell prompt is changed to the following


where oracle is the current user, db is the hostname, and /usr/local is the current working directory. A list of different customization options for shell prompts is given in Table 10-1.

Table 10-1: Environment Variable Setting for Different Command Prompts Under Bash





ASCII beep character



Date string

Wed Sep 6


Short hostname



Full hostname


Shell name



Current time (12-hour format)



Current time (24-hour format)



Current time (a.m./p.m. format)

10:54 a.m.





Shell version



Shell version with revision



Command history number



Privilege indicator



Username and privilege indicator



Username, command history number, and privilege indicator


At the shell prompt, you enter commands in the order in which you intend for them to be executed. For example, to execute the admintool from the command prompt, you would type this command:

oracle@db:/usr/sbin>> ./admintool

The ./ in this example indicates that the admintool application resides in the current directory—you could also execute the application with the following command, using its complete path:

oracle@db:/usr/sbin>> /usr/sbin/admintool

The admintool window would then appear on the desktop, assuming that you’re using a terminal window to execute a shell. Once the shell is executing a command in the foreground, like admintool, no other commands can be executed. However, by sending a command process into the background, you can execute more than one command in the shell. You can send a process into the background immediately by adding an ampersand (&) to the end of the command line:

oracle@db:/usr/sbin>> ./admintool &

Or, once a command has been executed, you can suspend it by pressing CTRL-Z, and then send it into the background by using the command bg:

oracle@db:/usr/sbin>> ./admintool
^Z[1] + Stopped (SIGTSTP)        admintool
oracle@db:/usr/sbin>> bg
[1] admintool&

The application name is displayed along with the job number. You can bring an application back into the foreground by using the following command:

oracle@db:/usr/sbin>> fg

This will bring job number 1 back into the foreground by default. However, if you had multiple jobs suspended, you would need to specify a job number with the fg command:

oracle@db:/usr/local/bin>> ./netscape
^Z[2] + Stopped (SIGTSTP)        netscape
oracle@db:/usr/sbin>> bg
[2] netscape&
oracle@db:/usr/sbin>> fg

You can obtain a list of all running jobs in the current shell by typing the following command:

$ jobs
[2] +  Running                 ./netscape&
[1] -  Running                 admintool&

Part I: Solaris 9 Operating Environment, Exam I