Executing commands through shell variable

Hey there,
I am trying to pass a command as argument to a function.
The command shows up in $1.
Now I want to execute this command, but if I do a $1

./sample
"bla/blaprintf: warning: ignoring excess arguments, starting with `bla/bla'

The code is :

#!/bin/ksh
fn()
{
$1
}

fn 'printf "bla/bla bla/bla bla bla bla bla\\n"'

Any ideas how to get it work please ?
Thanks,
Shrikant

Hi.

There is nothing wrong with your function.

The error

"bla/blaprintf: warning: ignoring excess arguments, starting with `bla/bla'

shows that the printf did run.

I get a different output:

/root/tmp/test # ./sample
"bla/bla/root/tmp/test # 

But there's nothing wrong with your thinking. i.e.

/root/tmp/test # cat sample
#!/bin/ksh
fn()
{
$1
}
fn ls
 
/root/tmp/test # ./sample
a  b  blah  c  file1  file2  sample  tst
/root/tmp/test # 

The problem you might be seing is with your printf itself.

Try:

eval "$1"

That would work!