Have you tried:
For the follow-on question of how to escape
* since it has special meaning when it's naked or in double quoted strings: use single quotes.
Or that would be:
If you want the content of
$cmd to be evaluated as shell code.
If you can't guarantee that
$cmd won't start with dash/minus (
-), which would cause eval in some shells like bash to treat it as an option, instead you may want to run:
eval " $cmd"
That extra leading space won't affect the way the command is parsed and will prevent
$cmd from being treated as an option to eval if it starts with
eval -- "$cmd" would also work in some shells (including bash) but is not POSIX (IIRC) and wouldn't work in dash or the Bourne shell for instance.
You don't need use
eval for even. Just put a dollar sign in front of the string: