开发者

How do you pass the string "*.*" to ruby as a command line parameter?

code:

  #test_argv.rb
  puts "length: #{ARGV.length} "
  ARGV.each do |a|
    puts "Argument: #{a}"
  end

If I supply the string "*.*" (with or without quotes) when I call the above, I get the following output:

  C:\test>test_argv *.*
  length: 5
  Argument: afile.TXT
  Argument: bfile.TXT
  Argument: cfile.TXT
  Argument: dfile.TXT
  Argument: somethingelse.TXT

i.e., a listing of the files in 开发者_Go百科c:\test.

Other values, like "s*.*" returns somethingelse.TXT, as you'd expect if you were doing file operations -- but I'm not.

But this behaves as would have expected:

  C:\test>test_argv asdf
  length: 1
  Argument: asdf

So my question is, how can I make a user-friendly script that will take "*.*" (etc) as a command line parameter? In addition, where is this documented/explained?

Edit: this happens on windows and linux, 1.8.7 and 1.9.2


You may need to put this into literal quotes:

test_argv "*.*"

The quotes should avoid having the command-line arguments get expanded on you prematurely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜