eval コマンドを使用します。eval コマンドは、実行時に構築された文字列を実行するために設計されています。
switch($timeOfDay) {
case "morning":
$shape = "circle";
break;
case "afternoon":
$shape = "sphere";
break;
case "evening":
$shape = "cone";
break;
default:
$shape = "cylinder";
}
eval $shape -r 5; // create specified shape with radius 5.
代わりに、次の関数構文で eval を使用することもできます。
eval ($shape+" -r 5");
また、evalEcho コマンドと evalDeferred コマンドを使用することもできます。