How do I execute a statement created at runtime?
 
 
 

Use the eval command. The eval command is designed to allow execution of a string that is built at runtime.

For example:

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.

Alternatively, you could use eval with function syntax:

eval ($shape+" -r 5");

You can also use the evalEcho and evalDeferred commands.