<<

. 21
( 69 .)



>>

was before you started the
new shell.

92
6
CUSTOMIZE YOUR SHELL



CHANGE YOUR SHELL
After you update the master password file, you need to

Y
ou can change your default shell from tcsh to bash
enter the changes into the NetInfo database. NetInfo is a
or zsh, so that the Terminal program automatically
database maintained by Mac OS X for keeping track of
starts with your preferred shell. You may never want
many things related to the operation of your computer,
to change your shell; the tcsh shell is a very useful and
including default shells. To make your shell change take
user-friendly shell program. However, many people like
effect in NetInfo, type the following command exactly as it
the bash shell, especially those from a Linux background, and
appears here:
you may wish to use that shell instead. For more information
about the different shells, see "Work with the Bourne-Again
sudo cat /etc/master.passwd | sudo niload -m
Shell" and "Work with the Z Shell" later in this chapter.
passwd /
Changing your shell is a two-step process. The first step is
This example uses the sudo command to allow you access
to use the chpass command to change your shell record in
to files and permissions you normally would not be able to
the master password file. You can update this file, which is
change. For this reason, you must make sure that you do
located at the pathname /etc/master.passwd, by typing the
not make a mistake typing the command. After you press
following:
the Return key, you see a prompt asking you to enter a
password. At this point, you can enter your normal user
chpass -s /path/to/shell
password and press Return.
For example, chpass -s /bin/zsh makes your default shell
the Z shell, and chpass -s /bin/bash changes your default
shell to the Bourne-again shell.

CHANGE YOUR SHELL




– The chpass command – This command updates the
„ Type chpass -s and a ‹ Type the command to
space. updates the master password update the NetInfo database NetInfo database, and
file. and press Return. changes your shell.
¤ Type the full pathname to
› Enter your password and
a shell and press Return.
press Return.

93
UNIX FOR MAC



WORK WITH THE BOURNE-AGAIN SHELL
You notice the second difference if you try to change your

Y
ou can use bash instead of tcsh as your primary shell,
shell settings. The Bourne-again shell uses different
or you can start the bash shell from the command
commands to set variables. To set a variable, for either shell
line. The Bourne-again shell is a popular alternative to
or environment, in the bash shell, you type the following:
tcsh, which is commonly used on Linux computers.
variable-name=value
The original shell on early Unix systems, /bin/sh, is known
as the Bourne shell after the programmer who wrote it,
No set or setenv command is necessary, just the variable
Steven Bourne. The bash shell takes its name from Bourne
name and value, separated by an equal sign. All variables are
in a clever play on words. The Bourne-again shell is more
automatically shell variables unless you export them as
compatible with the commands of the original /bin/sh
environment variables. To make the value of a variable
program than the tcsh shell, which is based on the later C
available as an environment variable for use by other
shell.
programs, you can type the command export variable-name.
If you are a typical user, you may not see a great difference
Another important difference is that the bash shell does not
between the tcsh and bash shells. You can type commands
run the commands in the .tcshrc file when you start a new
as you normally would, redirect output, and perform most
shell. Instead, it executes the commands in the .bashrc file
tasks without problems. The first obvious difference is a
in your Home directory.
change in your prompt, letting you know that you are now
running the bash shell.



WORK WITH THE BOURNE-AGAIN SHELL




– The shell starts a new bash ¤ Type export, a space, and
START BASH FROM TCSH SET AN ENVIRONMENT
VARIABLE
shell. the variable name, and press
„ Type /bin/bash and press
„ Type a variable name, Return.
Return.
then =, and the value of the – The variable is designated
variable, and press Return. as an environment variable.


94
6
CUSTOMIZE YOUR SHELL



WORK WITH THE Z SHELL
variables in tcsh ” by using the command setopt, and you

I
f you are an advanced user, you can write functions that
can set and export environment variables as you would in
perform shell tasks in the highly configurable Z shell. If
bash. Instead of running the contents of the .tcshrc file
you are new to Unix, this may be much more than you
when a shell starts, the zsh shell executes commands in the
need.
.zshrc file in your Home directory. Aliases in the zsh shell
must be set using the following syntax, which differs from
The differences between shells are most apparent when you
the tcsh shell by the requirement of an equal sign:
are writing shell scripts, as these scripts use the advanced
features of the shell. The Z shell uses a number of functions
alias short-alias='command and options'
that you can define in order to override or change default
behavior.
You can take full advantage of the extensibility of the Z shell
by creating specialized functions in your .zshrc file. A
The Z shell was created to be compatible with another early
function creates a command, similar to an alias but with
shell known as the Korn shell, or ksh. If you are going to be
more flexibility and control. To learn about Z shell
using your shell a great deal and want to become more
functions, you can see the manual pages for zsh by typing
familiar with shell customization, the Z shell may be a good
man zsh.
choice for you.

Many of the built-in commands familiar from the tcsh shell
have different command names and values in the zsh shell.
For example, you can set zsh shell options ” similar to shell


WORK WITH THE Z SHELL




– The shell starts a new zsh ‹ Press Return.
START ZSH FROM TCSH CREATE A SIMPLE
Z SHELL FUNCTION
shell.
„ Type /bin/zsh and press – The Z shell defines a new
„ Type function cp(), a
Return. command named cp.
space, and then type {.
¤ Type command cp -i "$@",
a space, and then type }.
95
UNIX FOR MAC




SUSPEND THE CURRENT PROCESS
and suspend them if you have sufficient privileges. You can

Y
ou can suspend a process to regain control of the
also move processes to the background so that you can
command line, and from that point, kill the process,
issue other commands.
move it into the background, or leave it suspended
until you are ready to restart it. Just as almost everything that
Every process has a process ID ” a unique numeric
makes up a Unix system is a file, almost everything that a
identifier that the system assigns. While you enter a
Unix system does is a process. The shell that responds to the
command in your shell, that shell is an active process.
commands you enter in a Terminal window is a process.
When you press Return, the command that you just
Each command you enter is a process. When you ask the
entered starts running, and your shell is suspended until
system what processes are currently running, that too is a
that process completes.
process. Just as Unix makes little distinction between system
files, application files, and personal files, it makes little You can suspend a process by pressing Control + Z. When
distinction between system processes, applications, and the you suspend a process, it cannot run. It does not access
commands that you enter in a Terminal window. The activity files, accumulate run time, or task the CPU. A suspended
of the system is implemented as a series of processes. process is also referred to as a stopped job.
Unlike some operating systems, Unix systems like Mac OS X
allow you to gather a lot of information about the processes
that are running on your system. In fact, you can start, stop,

SUSPEND THE CURRENT PROCESS




– The find command starts – The system ignores the
¤ Type date and press
RUN SEQUENTIAL COMMANDS
looking for a file named ps. Return. date command, storing it
„ In a Terminal window, in a queue, until the find
– The find command
type the command find /usr
command finishes.
-name ps “print and press generates a lot of output.
Return.




96
7
WORK WITH PROCESSES



On a multiprocessing system such as Unix, many processes appear to
be running at the same time. They are actually running in quick
succession, taking turns using the system's CPU and memory. The
system tracks the resources that each process requires and restores
the process environment as needed each time a process gets its turn
to run. At almost any instant in time, most processes are waiting for
some resource, whether that resource is a response from the user,
data from the disk, or simply a turn at the processor.
Processes change state frequently while they are running. Process
states include running, sleeping, stopped, and terminated.
When you suspend a process, you essentially put it on hold so that
you can run other commands. Similar to putting a caller on hold,
suspending a process means that no progress is made as long as that
process is suspended. The process is stopped, awaiting your instruction
to start again or to terminate and release all of its resources.
You can open a second Terminal window when you are working on
the system, but this is not an option if you are logged in remotely.




– Unix assigns a job number – The system responds with
¤ Press Control + Z to
SUSPEND A PROCESS
suspend the process. to the suspended process and another prompt indicating
„ Type man date and press displays its process ID. that you have control of
‹ Press Return.
Return.
the shell.


<<

. 21
( 69 .)



>>