2013-10-01 88 views
2

的朋友,在如何給OPTARG b *值在getopt的類

gnu.getopt.Getopt.jar

有一些問題,我得到了一些問題,當我給B *作爲選項參數,那麼它正在以bin

Getopt g = new Getopt("cm_log_parser", args, "i:s"); //-D to enable debug log 


while((opt = g.getopt()) != -1) 
{ 
    switch (opt) 
    { 
     case 'f'://To set file name(if above is not specified) 
      fileNameWithPath = getAndCheckOptArg(fFlag, opt, g); 
      fFlag = true; 
      break; 

     case 'p'://To set the pattern 
      String pattern = g.getOptarg(); 
      hFlag = true; 
      break; 

     case '?': 
      usage("Invalid option" + opt + " option"); 
      break; 
    } 
} 

當我指定-p "b*"這是回報bin,爲什麼發生這種情況?

回答

1

殼(我懷疑你使用Linux,是吧?)解決了b*字面來bin(必須有一個在當前工作目錄中名爲bin目錄),因爲它是作爲通配符處理。

根據您使用的shell,你必須躲避星號...例如在bash,使用

-p b\* 

爲了躲避它是一個星號,而不是由shell得到解決