EVAL(1POSIX)
πΈ EVAL(1POSIX) πΈ
okay bestie, welcome to the POSIX Programmer's Manual π this one is the EVAL(1POSIX) page, and before we get into it, a lil heads-up from the PROLOG: this manual page is part of the POSIX Programmer's Manual, and the Linux implementation of this interface may differ β so if you're on Linux, go peek at the corresponding Linux manual page for the deets on Linux behavior. also possible: the interface just isn't implemented on Linux at all. π so vibe check your platform first, k?
β¨ NAME β¨
eval β construct command by concatenating arguments π
like, it builds a command out of your args and then the shell runs it. main character energy fr.
π¦ SYNOPSIS π¦
eval [argument...]
π DESCRIPTION π
okay so here's the tea β the eval utility shall construct a command by concatenating arguments together, separating each with a <space> character. then β and this is the iconic part β the constructed command shall be read and executed by the shell. it's giving "make the shell do the thing you just built." β¨
π OPTIONS π
None.
literally none. zero. no flags, no options, nothing to remember, we love a low-maintenance queen π
π OPERANDS π
See the DESCRIPTION. (yep, that's the whole vibe β the arguments are the operands, go read DESCRIPTION again bestie π«Ά)
π STDIN π
Not used.
π§ INPUT FILES π§
None.
π ENVIRONMENT VARIABLES π
None.
β ASYNCHRONOUS EVENTS β
Default.
πΈ STDOUT πΈ
Not used.
π STDERR π
The standard error shall be used only for diagnostic messages. so if something's wrong, that's where the drama shows up π
π OUTPUT FILES π
None.
π¦ EXTENDED DESCRIPTION π¦
None.
π₯ EXIT STATUS π₯
okay so listen up, this part matters:
- If there are no arguments, or only null arguments,
evalshall return a zero exit status. - Otherwise, it shall return the exit status of the command defined by the string of concatenated arguments separated by
<space>characters. - OR a non-zero exit status if the concatenation could not be parsed as a command and the shell is interactive (and therefore did not abort).
so like... no args = happy zero. real args = whatever that command said. garbage that won't parse + interactive shell = non-zero, we're not aborting, we're just sad. π
π CONSEQUENCES OF ERRORS π
Default.
β οΈ heads up: the following sections are informative. (translation: not the normative rules, more like the commentary track π¬)
π APPLICATION USAGE π
so here's a lil cautionary tale: since eval is not required to recognize the "--" end of options delimiter, if the argument(s) to eval might begin with '-', it's recommended that the first argument is prefixed by a string that will not alter the commands to be executed β such as a <space> character:
eval " $commands"
or:
eval " $(some_command)"
see that sneaky lil space at the front? that's the whole trick. protect yourself bestie π«Ά
π EXAMPLES π
okay this example is a whole journey, watch:
foo=10 x=foo
y='$'$x
echo $y
$foo
eval y='$'$x
echo $y
10
the way that second echo $y hits different after the eval... that's the power of double expansion, no cap β¨
π RATIONALE π
This standard allows, but does not require, eval to recognize "--". Although this means applications cannot use "--" to protect against options supported as an extension (or errors reported for unsupported options), the nature of the eval utility is such that other means can be used to provide this protection (see APPLICATION USAGE above). π§ so like, yeah, "--" might not save you here, but the space trick from APPLICATION USAGE will. iykyk.
π FUTURE DIRECTIONS π
None.
π SEE ALSO π
- Section 2.14, Special Built-In Utilities
go read that one too, it's basically the friend group this utility runs with π«Ά
β COPYRIGHT β
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 .
and that's the page, bestie π brought to you by IEEE/The Open Group, 2017 β yeah, 2017, the standard is a lil vintage but she still ate. periodt. πβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix 2017a-2 Β· Other
- debian trixie: manpages-posix 2017a-2 Β· Other
- ubuntu jammy: manpages-posix 2017a-2 Β· Other
- ubuntu noble: manpages-posix 2017a-2 Β· Other
- ubuntu resolute: manpages-posix 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms