1EXEC(1P)                   POSIX Programmer's Manual                  EXEC(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       exec - execute commands and open, close, or copy file descriptors
13

SYNOPSIS

15       exec [command [argument ...]]
16

DESCRIPTION

18       The exec utility shall open, close, and/or  copy  file  descriptors  as
19       specified by any redirections as part of the command.
20
21       If  exec  is  specified  without  command  or  arguments,  and any file
22       descriptors with numbers greater than 2 are opened with associated  re‐
23       direction  statements, it is unspecified whether those file descriptors
24       remain open when the shell invokes another utility.  Scripts  concerned
25       that  child  shells could misuse open file descriptors can always close
26       them explicitly, as shown in one of the following examples.
27
28       If exec is specified with command, it shall replace the shell with com‐
29       mand  without creating a new process.  If arguments are specified, they
30       shall be arguments to command.  Redirection affects the  current  shell
31       execution environment.
32

OPTIONS

34       None.
35

OPERANDS

37       See the DESCRIPTION.
38

STDIN

40       Not used.
41

INPUT FILES

43       None.
44

ENVIRONMENT VARIABLES

46       None.
47

ASYNCHRONOUS EVENTS

49       Default.
50

STDOUT

52       Not used.
53

STDERR

55       The standard error shall be used only for diagnostic messages.
56

OUTPUT FILES

58       None.
59

EXTENDED DESCRIPTION

61       None.
62

EXIT STATUS

64       If  command  is  specified, exec shall not return to the shell; rather,
65       the exit status of the process shall be the exit status of the  program
66       implementing  command,  which  overlaid  the  shell.  If command is not
67       found, the exit status shall be 127. If command is found, but it is not
68       an  executable  utility, the exit status shall be 126. If a redirection
69       error occurs (see Consequences of Shell Errors ), the shell shall  exit
70       with  a  value  in the range 1-125. Otherwise, exec shall return a zero
71       exit status.
72

CONSEQUENCES OF ERRORS

74       Default.
75
76       The following sections are informative.
77

APPLICATION USAGE

79       None.
80

EXAMPLES

82       Open readfile as file descriptor 3 for reading:
83
84
85              exec 3< readfile
86
87       Open writefile as file descriptor 4 for writing:
88
89
90              exec 4> writefile
91
92       Make file descriptor 5 a copy of file descriptor 0:
93
94
95              exec 5<&0
96
97       Close file descriptor 3:
98
99
100              exec 3<&-
101
102       Cat the file maggie by replacing the current shell with the  cat  util‐
103       ity:
104
105
106              exec cat maggie
107

RATIONALE

109       Most historical implementations were not conformant in that:
110
111
112              foo=bar exec cmd
113
114       did not pass foo to cmd.
115

FUTURE DIRECTIONS

117       None.
118

SEE ALSO

120       Special Built-In Utilities
121
123       Portions  of  this text are reprinted and reproduced in electronic form
124       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
125       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
126       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
127       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
128       event of any discrepancy between this version and the original IEEE and
129       The  Open Group Standard, the original IEEE and The Open Group Standard
130       is the referee document. The original Standard can be  obtained  online
131       at http://www.opengroup.org/unix/online.html .
132
133
134
135IEEE/The Open Group                  2003                             EXEC(1P)
Impressum