this works for me:
CMD="ls -la" $CMD
while this always fails:
CMD="sed -e 's|abc|abc|g' file" $CMD
with the error message:
sed: -e expression #1, char 1: unknown command: `''
That's because when you enter the command on the command line, shell runs "expansions" on it. The last step is "Quote Removal", but it only removes quotes that weren't a result of any expansion. (See EXPANSIONS in
man bash for details.) Here, the quotes are part of the variable expansion, so they're not removed.
You can enter the substitution without quotes to make it work:
cmd='sed -e s|abc|abc|g file' $cmd