+1  A: 

From the couple of lines of your question, I would have expected some approach like this:

#!/bin/bash

while read -r line; do
    # munge $line
    if eval "$line"; then
        # success
    else
        # fail
    fi
done

Where you have backticks in the source, you'll have to escape them to avoid evaluating them too early. Also, backticks aren't the only way to evaluate code - there is eval, as shown above. Maybe it's eval that you were looking for?

For example, this line:

CMD[1]=`pgrep -u root -d , sshd 1>/dev/null; echo $?`

Ought probably look more like this:

CMD[1]='`pgrep -u root -d , sshd 1>/dev/null; echo $?`'
Barry Kelly
This works! However, per my and your earlier comments (we agree) I don't want back ticks in there. This script will not live on any other environments outside of Linux, I have no control over BASH and agree with your portability concern!
Eric M
+1  A: 

First of all, you should never use backticks unless you need to be compatible with an old shell that doesn't support $() - and only then.

Secondly, I don't understand why you're setting CMD[1] but then calling CMD[$i] with i set to 2.

Anyway, this is one way (and it's similar to part of Barry's answer):

CMD[1]='$(date;date)'    # no backticks (remember - they carry Lime disease)
eval echo "${CMD[1]}"    # or $i instead of 1
Dennis Williamson
This also works. I hadn't thought of this method. Excellent, Thank You!
Eric M