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, eval shall 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 🫢


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