EVAL(1P)

๐Ÿ’… EVAL(1P) โ€” the POSIX Programmer's Manual page, but make it cute โœจ

okay bestie, real talk: this is the EVAL(1P) page from the POSIX Programmer's Manual. That's the whole header, we're moving on ๐Ÿ’–


๐ŸŽ€ PROLOG ๐ŸŽ€

so like, this manual page is part of the POSIX Programmer's Manual. but heads up: the Linux implementation of this interface may differ โ€” so if you're on Linux, go read the corresponding Linux manual page for the actual tea โ˜•. or... the interface might just not be implemented on Linux at all. rip ๐Ÿ™ˆ


๐ŸŒธ NAME ๐ŸŒธ

eval โ€” construct command by concatenating arguments

like. it builds a whole command out of your lil argument pieces. that's the job. that's the gig. ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

eval [argument...]

๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

okay so the eval utility shall construct a command by concatenating arguments together, separating each one with a <space> character. then โ€” and this is the main character moment โ€” the constructed command shall be read and executed by the shell. ๐Ÿฆ‹

it's giving "build a command, then immediately run it." no cap.


๐Ÿ”ฅ OPTIONS ๐Ÿ”ฅ

None.

literally none. not a single flag. we love a low-maintenance icon ๐Ÿ’…


๐Ÿ“ OPERANDS ๐Ÿ“

See the DESCRIPTION. (they're the arguments, bestie, they're the whole point)


๐ŸŒˆ STDIN ๐ŸŒˆ

Not used. it doesn't want your input, it's busy โœ‹


๐Ÿงš INPUT FILES ๐Ÿงš

None.


โญ ENVIRONMENT VARIABLES โญ

None. no env vars needed, she's self-sufficient ๐Ÿ’–


๐Ÿ’ซ ASYNCHRONOUS EVENTS ๐Ÿ’ซ

Default.


๐Ÿซถ STDOUT ๐Ÿซถ

Not used. nothing gets printed by eval itself, it just does things.


๐Ÿ’€ STDERR ๐Ÿ’€

The standard error shall be used only for diagnostic messages. that's it. only for diagnostics. don't expect small talk.


๐ŸŽ€ OUTPUT FILES ๐ŸŽ€

None.


๐ŸŒธ EXTENDED DESCRIPTION ๐ŸŒธ

None. there is no extended description. this section is just standing there. respectfully. ๐Ÿ™ˆ


๐Ÿ‘‘ EXIT STATUS ๐Ÿ‘‘

okay this part actually matters, listen up:

  • 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)
โš ๏ธ note the little "and therefore did not abort" โ€” if the shell is interactive it doesn't just die, it hands you a non-zero status instead. know the difference, bestie, it's important ๐Ÿ˜ญ

๐Ÿฆ‹ CONSEQUENCES OF ERRORS ๐Ÿฆ‹

Default.

psst โ€” the following sections are informative. (translation: they're helpful commentary, not requirements โœจ)

๐Ÿ’… APPLICATION USAGE ๐Ÿ’…

okay so here's the situation: eval is not required to recognize the "--" end of options delimiter. so in cases where the argument(s) to eval might begin with '-', it is 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 what she did there? a lil sneaky space at the front, and suddenly your args can't get mistaken for options. iconic behavior. ๐ŸŽ€


๐ŸŒŸ EXAMPLES ๐ŸŒŸ

here's the whole vibe, verbatim:

foo=10 x=foo
y='$'$x
echo $y
$foo
eval y='$'$x
echo $y
10

watch the eval line do its lil magic and turn $y into an actual 10. ate. ๐Ÿ”ฅ


๐Ÿง  RATIONALE ๐Ÿง 

This standard allows, but does not require, eval to recognize "--".

and yes, that means applications cannot use "--" to protect against options supported as an extension (or errors reported for unsupported options). BUT โ€” and this is the slay part โ€” the nature of the eval utility is such that other means can be used to provide this protection (see APPLICATION USAGE above ๐Ÿ’–).


๐Ÿ”ฎ 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 .


and that's the whole page, bestie ๐Ÿซถ โ€” brought to you by IEEE/The Open Group, dated 2017, for EVAL(1P). go forth and concatenate responsibly. periodt. ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from