Assigning command to a variable

I've been searching these forums for a while, but this is my first actual post, so please bear with me :slight_smile:

I'm writing a short script using ksh and am trying to store a command and parameters in a variable. My intention is to issue the command by calling the variable. The command will contain double quotes. My problem is that for some reason there's no output.

Here's a simplified view of what I'm trying to accomplish (find command is used just as an example of the problem):

#!/usr/bin/ksh
cmd="find . -name \"55*\""
echo $cmd
$cmd

The only output is what I echo'ed:

# ./problem.sh
find . -name "55*"

If I issue the same command outside of the script, I get the desired result:

# find . -name "55*"
./55_messages.txt

Is is possible to store a command+parameters in a variable and run the command through the variable?

Thanks,
Hubert

 
#!/usr/bin/ksh
cmd="find . -name \"55*\""
echo $cmd
$cmd

Any command in a variable, use eval

cmd="find . -name 55\*"
eval $cmd

not ""

try `` instead

Wouldn't that just put the output from the ls into the variable, then try to run it (ie execute something like "-rw-r--r--")?

eval! Thank you edidataguy! This did the trick :b:

---------- Post updated 08-11-09 at 12:00 AM ---------- Previous update was 08-10-09 at 11:59 PM ----------

Yeah, that would capture the output from 'ls -l' into a variable. I found many hits for doing that, but unfortuantely not the opposite which is what I wanted to accomplish :slight_smile:

Thanks tho guys!