eval - Man Page

construct command by concatenating arguments

Prolog

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

Synopsis

eval [argument...]

Description

The eval utility shall construct a command by concatenating arguments together, separating each with a <space> character. The constructed command shall be read and executed by the shell.

Options

None.

Operands

See the Description.

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.

Output Files

None.

Extended Description

None.

Exit Status

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).

Consequences of Errors

Default.

The following sections are informative.

Application Usage

Since eval is not required to recognize the "--" end of options delimiter, 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)"

Examples

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

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).

Future Directions

None.

See Also

Section 2.14, Special Built-In Utilities

Info

2017 IEEE/The Open Group POSIX Programmer's Manual