It's not a big story, but I'm a little worried, so it's a memo.
The'**' wildcard is useful, isn't it? However, when I passed it to options with ruby, the behavior was strange.
It is a shell. So fish will receive'** /', but bash won't. So what about ruby?
ruby hage.rb */hoge.
When you write, fish will expand it in advance.
p ARGV[0]
p ARGV
> ruby bin/calc_site_ks.rb **/d_ein*.o*
"double_new_model/vol_098/d_ein_098.o22192"
["double_new_model/vol_098/d_ein_098.o22192", "double_new_model/vol_100/d_ein_100_0_24.o22179", "double_new_model/vol_100/d_ein_100_24_44.o22180", "double_new_model/vol_102/d_ein_102.o22194", "double_new_model/vol_104/d_ein_104.o22195"]
ruby hage.rb '*/hoge.'
If you write, it will not expand.
> ruby bin/calc_site_ks.rb '**/d_ein*.o*'
"**/d_ein*.o*"
["**/d_ein*.o*"]
So, after that, expand it with Dir.glob (ARGV [0]).
In normal command usage, it is not enclosed in quotes and is expanded as it is. In that case, the order of options is important. Be careful if you use optparse or thor, but you may need to be a little careful with the command you usually use.
Start ruby also specifies the specifications. Says,
The string specified in argument is set as the initial value of the built-in constant Object :: ARGV. In environments where the standard shell does not expand wildcards (Win32), the Ruby interpreter expands the wildcards and sets it to Object :: ARGV. In this case you can use
*',
?',[]',
** /'as wildcards. In the Win32 environment, if you want to suppress wildcard expansion, enclose the argument in single quotes (').
Recommended Posts