
664
|
Chapter 6: The Bash Shell and Korn Shell
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
exec
exec [command args ...]
exec [-a name] [-cl] [command args ... ]
Execute command in place of the current process (instead of
creating a new process). exec is also useful for opening, closing, or
copying file descriptors. The second form is for ksh93 and Bash.
Options
-a Use name for the value of argv[0].
-c Clear the environment before executing the program.
-l Place a minus sign at the front of argv[0], just as login(1) does.
Bash only.
Examples
trap 'exec 2>&-' 0 Close standard error when
shell script exits (signal 0)
$ exec /bin/csh Replace shell with C shell
$ exec < infile Reassign standard input to infile
exit
exit [n]
Exit a shell script with status n (e.g., exit 1). n can be 0 (success) or
nonzero (failure). If n is not given, exit status is that of the most
recent command. exit can be issued at the command line to close a
window (log out). Exit statuses can range in value from 0 to 255.
Example
if [ $# -eq 0 ]
then
echo "Usage: $0 [-c] [-d] file(s)" 1>&2
exit 1 # Error status
fi
export
export [variables]
export [name=[value] ...]
export -p
export [-fn] [name=[value] ...]
Pass (export) the value of one or more shell variables, giving global
meaning to the variables (which are local by default). For example,
a variable defined in one shell script ...