概要

eval はシェル組み込みコマンドで、引数として与えられた文字列をもう一度シェルに解釈させて実行するコマンド

eval [arguments]
The arguments are concatenated together into a single command, separated by spaces. Bash then reads and executes this command and returns its exit status as the exit status of eval. If there are no arguments or only empty arguments, the return status is zero.

引数の文字列を1つに連結し、その文字列をシェルに読み込ませて実行する

なぜ必要か

UNIX シェルでは、プロセスは自分より上位のプロセスの環境を直接変更できない

例:

$ export MYVAR="hello"
$ ( export MYVAR="world" )
$ echo $MYVAR
hello

サブシェル ( … ) 内で環境変数を書き換えても、親シェルには反映されない。

そのため、現在のシェルで環境変数を反映させたい、と言った場合にeval実行する必要があるケースがある