The eval built-in evaluates operands as commands.

Syntax

  • eval [-i] [command…]

The eval built-in requires that all options precede operands. Any command line arguments after the first operand are all treated as operands.

Description

The eval parses operands as commands and executes them in the current command execution environment.

When executed without the -i (--iteration) option, all the operands are concatenated into one string (with a space inserted between each operand) and parsed/executed at once.

With the -i (--iteration) option, the built-in performs iterative execution: operands are parsed/executed one by one. If the continue built-in is executed with the -i (--iteration) option during the iterative execution, the execution of the current operand is aborted and the next operand is parsed/executed immediately. The break built-in with the -i (--iteration) option is similar but the remaining operands are not parsed/executed. The value of the ? special parameter is saved before the iterative execution is started. The parameter value is restored to the saved one after each iteration.

Options

-i
--iteration

Perform iterative execution.

Operands

command

A string that is parsed and executed as commands.

Exit status

The exit status is zero if no command was specified or command contained no actual command that can be executed. Otherwise, that is, if the eval built-in executed one or more commands, the exit status of the eval built-in is that of the last executed command.

Notes

The eval built-in is a special built-in.

The POSIX standard defines no options for the eval built-in; the built-in accepts no options in the POSIXly-correct mode.