eval

A shell builtin that joins its arguments into one string and runs that string as a command, as if you had typed it.

Any text from outside that reaches eval runs as code with the script's permissions.

In more detail

The text is expanded a second time, so any quote, semicolon or $( ) that arrives inside data becomes live code, and eval on untrusted input is command injection. A common safe use is running trusted setup output, such as eval "$(brew shellenv)", which sets PATH and other variables in the current shell. Only eval text you trust, because it runs with your full permissions.

Related terms

Taught in

References

Certification courses