LinuxCommandLibrary

eval

shell builtin for dynamic command execution

TLDR

Evaluate and execute arguments

$ eval "[echo \$HOME]"
copy
Execute dynamically built command
$ cmd="ls -la"; eval "$cmd"
copy
Expand variables twice
$ var="PATH"; eval "echo \$$var"
copy
Execute command from variable
$ action="date"; eval "$action"
copy

SYNOPSIS

eval [argument...]

DESCRIPTION

eval is a shell builtin that concatenates its arguments, performs shell expansions, and executes the result as a command. It 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).
eval's two-pass evaluation makes it powerful but also potentially dangerous with untrusted input.

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 shell builtin, present in Bourne shell and all its derivatives. It provides essential metaprogramming capabilities for shell scripts.

SEE ALSO

bash(1), sh(1), exec(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community