executing variables in ksh scripts?

In a ksh script on an AIX box running a jillion oracle database processes, I'm setting a variable to one of two possible arguments, depending on cmd line arguments.

FINDIT="ps -ef | grep oracle | grep DBexport | grep rshrc"
-or-
FINDIT="ps -ef | grep oracle | grep prod | grep runback"

I want to have a way to execute the command list defined by the variable $FINDIT later in the script, putting the result in another variable. Any ideas how?

Things I have tried:

  1. The straightforward RESULT=`$FINDIT`
    (I get a usage on ps)

  2. Putting the list in braces gives me bad substitution
    FINDIT=${list}

  3. exec is not on the system.

With either of the possible values of $FINDIT, if I execute them on the command line, there is no problem. What am I doing wrong?

Thanks,
-zedmelon

Try something like this:

Remember to check for proper number of arguments and such. Probably also want to send stderr to /dev/null to avoid errors (if any)

find_them () {

ARG1=$1
ARG2=$2

ps -ef | grep oracle | grep $1 | grep $2 > /tmp/found_them.txt

}

Now execute this function when ever you need it, passing in your two search strings and use the resulting /tmp file as needed.

Use:
RESULT=$(eval $FINDIT)

Google...

That was a great idea. And if I weren't so short-sighted, I'd have tried that. Of course, since I'm lazy, I would have shortened it even more:

find_them () {
ARG1=$1
ARG2=$2
RESULT=`ps -ef | grep oracle | grep $1 | grep $2`
}

Perderabo...

Thanks! Since I'm lazy and 'eval' is shorter than creating a function, I tried that first, and it worked on the command line. I'm betting it'll work in the script as well. Of course, this is monitoring a process that runs 1/week, so I'll confirm next Tuesday...
:frowning:

Anyway, Thanks to both of you. It's greatly appreciated.

-zedmelon