On Mon, Mar 04, 2002 at 11:38:02PM +0900, Yohanes Santoso wrote:
> Suppose I have cmd=["echo", "*", "*"], I want to unroll this cmd so
> that when I call system, it calls, in effect, system("echo", "*",
> "*").
> 
> The number of argument to echo is known only at run-time. Currently
> I'm concat-ing them into a string with each argument double-quoted to
> prevent shell expansion: cmd="echo \"#{arg1}\"". Any better way?

You have two options, depending on what you want to do:

  cmd = ["echo", "*", "*"]
  system(*cmd)              #=> * *
  system(cmd.join(' '))     #=> foo.c foo.rb foo.rb~

I'm not sure how Ruby decides to execute the given command; this has
always been something of a mystery to me.

Paul