EXEC(1P)

🌸 PROLOG 🌸

okay so bestie, real talk for a sec β€” this page is part of the POSIX Programmer's Manual. the Linux version of this interface might do its own lil thing (so go check the matching Linux manual page if you need the Linux deets), or honestly it might not even be implemented on Linux at all. not us being mysterious, it's just how it is πŸ’…


✨ NAME ✨

exec β€” execute commands and open, close, or copy file descriptors 🫢


🌈 SYNOPSIS 🌈

exec [command [argument...]]

πŸ’– DESCRIPTION πŸ’–

so the exec utility shall open, close, and/or copy file descriptors, as specified by any redirections that are part of the command. that's the whole job, and it eats every time πŸ”₯

if exec is specified with no command or arguments, and any file descriptors with numbers greater than 2 are opened with associated redirection statements, it is unspecified whether those file descriptors remain open when the shell invokes another utility. like, genuinely unspecified, we're not being coy. scripts that are worried about child shells misusing open file descriptors can always close them explicitly, as shown in one of the examples down below πŸ‘‡

if exec is specified with command, it shall replace the shell with command without creating a new process. main character energy fr β€” the shell doesn't stick around, it becomes the command. and if arguments are specified, they shall be arguments to command. redirection affects the current shell execution environment. periodt.


πŸŽ€ OPTIONS πŸŽ€

None. like, literally none. zero. empty. the void. πŸ™ˆ


πŸ¦‹ OPERANDS πŸ¦‹

see the DESCRIPTION. yeah bestie, it's up there, we already spilled ☝️


⭐ STDIN ⭐

not used. doesn't even look at it πŸ’€


πŸ’œ INPUT FILES πŸ’œ

none.


🌸 ENVIRONMENT VARIABLES 🌸

none.


🧚 ASYNCHRONOUS EVENTS 🧚

default.


πŸ“ STDOUT πŸ“

not used.


🌈 STDERR 🌈

the standard error shall be used only for diagnostic messages. that's its whole lane, don't ask it for more.


πŸ’… OUTPUT FILES πŸ’…

none.


✨ EXTENDED DESCRIPTION ✨

none.


πŸ‘‘ EXIT STATUS πŸ‘‘

okay this part actually matters so lock in πŸ”’

if command is specified, exec shall not return to the shell; rather, the exit status of the process shall be the exit status of the program implementing command, which overlaid the shell. (yes, "overlaid." the shell is gone. it's giving metamorphosis πŸ¦‹)

if command is not found, the exit status shall be 127.

if command is found, but it is not an executable utility, the exit status shall be 126.

if a redirection error occurs (see Section 2.8.1, Consequences of Shell Errors), the shell shall exit with a value in the range 1-125.

otherwise, exec shall return a zero exit status. slay. βœ…


πŸ’€ CONSEQUENCES OF ERRORS πŸ’€

default.

the following sections are informative. (translation: the drama is over, this is bonus content 🎁)


🌟 APPLICATION USAGE 🌟

none.


πŸ”₯ EXAMPLES πŸ”₯

open readfile as file descriptor 3 for reading:

exec 3< readfile

open writefile as file descriptor 4 for writing:

exec 4> writefile

make file descriptor 5 a copy of file descriptor 0:

exec 5<&0

close file descriptor 3:

exec 3<&-

cat the file maggie by replacing the current shell with the cat utility:

exec cat maggie

not the exec cat maggie being the most iconic one here 😭 she said "i'm not reading the file, i'm becoming the reader"


🧠 RATIONALE 🧠

most historical implementations were not conformant in that:

foo=bar exec cmd

did not pass foo to cmd. yeah. they fumbled that one. we said what we said πŸ™ˆ


🌈 FUTURE DIRECTIONS 🌈

none.


πŸ’– SEE ALSO πŸ’–

Section 2.14, Special Built-In Utilities


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


okay that's the whole page bestie, we ate and left no crumbs πŸ’…βœ¨ this one's from IEEE/The Open Group, 2017 β€” exec(1P), that's the one, go forth and exec responsibly 🫢🌈

πŸ“¦ where this page comes from