eval
shell builtin for dynamic command execution
TLDR
SYNOPSIS
eval [argument...]
DESCRIPTION
eval is a POSIX special shell builtin that concatenates its arguments separated by spaces, then reads and executes the resulting string as a shell command. This enables dynamic command construction and double expansion of variables.
The command is useful when command strings are built programmatically or stored in variables. It allows variable indirection (accessing a variable whose name is in another variable). A common real-world use is initializing ssh-agent with `eval "$(ssh-agent -s)"`.
If there are no arguments or only null arguments, eval returns exit status 0. Otherwise it returns the exit status of the executed command.
PARAMETERS
ARGUMENT
Arguments to concatenate and execute.
CAVEATS
Security risk with untrusted input. Can execute arbitrary commands. Debugging eval'd commands is difficult. Quoting must be handled carefully.
HISTORY
eval is a standard POSIX special shell builtin defined in IEEE Std 1003.1 (POSIX.1), present in the original Bourne shell and all its derivatives including bash, zsh, ksh, and dash. It provides essential metaprogramming capabilities for shell scripts.
