0

我有一个 shell 脚本,它执行一个带有从不同 Java 程序返回的参数的 Java 程序。

java -cp $wekaPath $(java GetFilter $WandFDir) -i $(pwd)/temp/training"$i"_$arffName.arff -o $(pwd)/temp/training_"$i"_$arffName.arff

回显时,它会产生以下字符串:

java -cp /home/robobenny/Documents/WEKA/weka-3-7-4/weka.jar weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.InfoGainAttributeEval" -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N 20" -c first -i /home/robobenny/Documents/WEKA/Pipeline/temp/training1_Test.arff -o /home/robobenny/Documents/WEKA/Pipeline/temp/training_1_Test.arff

这很好,因为如果我将字符串复制到命令行,它会毫无意外地运行 Java 程序。当我不回显它并尝试从 shell 脚本执行它时,就会出现问题,我从终端得到以下信息:

<!-- language: lang-none -->
Can't find class called: "weka.attributeSelection.InfoGainAttributeEval"
Filter options:

-S <"Name of search class [search options]">
    Sets search method for subset evaluators.
    eg. -S "weka.attributeSelection.BestFirst -S 8"
-E <"Name of attribute/subset evaluation class [evaluator options]">
    Sets attribute/subset evaluator.
    eg. -E "weka.attributeSelection.CfsSubsetEval -L"

Options specific to evaluator weka.attributeSelection.CfsSubsetEval:

-M
    Treat missing values as a separate value.
-L
    Don't include locally predictive attributes.

Options specific to search weka.attributeSelection.BestFirst:

-P <start set>
    Specify a starting set of attributes.
    Eg. 1,3,5-7.
-D <0 = backward | 1 = forward | 2 = bi-directional>
    Direction of search. (default = 1).
-N <num>
    Number of non-improving nodes to
    consider before terminating search.
-S <num>
    Size of lookup cache for evaluated subsets.
    Expressed as a multiple of the number of
    attributes in the data set. (default = 1)

General options:

-h
    Get help on available options.
    (use -b -h for help on batch mode.)
-i <file>
    The name of the file containing input instances.
    If not supplied then instances will be read from stdin.
-o <file>
    The name of the file output instances will be written to.
    If not supplied then instances will be written to stdout.
-c <class index>
    The number of the attribute to use as the class.
    "first" and "last" are also valid entries.
    If not supplied then no class is assigned.

当我硬编码$(java GetFilter $WandFDir)shell脚本中的输出时:

java -cp $wekaPath weka.filters.supervised.attribute.AttributeSelection -E "weka.attributeSelection.InfoGainAttributeEval" -S "weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N 20" -c first -i $(pwd)/temp/training"$i"_$arffName.arff -o $(pwd)/temp/training_"$i"_$arffName.arff

它也正常运行。有趣的是,当回显时,双引号消失了。

java -cp /home/robobenny/Documents/WEKA/weka-3-7-4/weka.jar weka.filters.supervised.attribute.AttributeSelection -E weka.attributeSelection.InfoGainAttributeEval -S weka.attributeSelection.Ranker -T -1.7976931348623157E308 -N 20 -c first -i /home/robobenny/Documents/WEKA/Pipeline/temp/training2_Test.arff -o /home/robobenny/Documents/WEKA/Pipeline/temp/training_2_Test.arff

当我在输出中留下双引号时,出现$(java GetFilter $WandFDir)以下错误:

<!-- language: lang-none -->
Illegal options: -T -1.7976931348623157E308 -N 20 
Filter options:

-S <"Name of search class [search options]">
    Sets search method for subset evaluators.
    eg. -S "weka.attributeSelection.BestFirst -S 8"
-E <"Name of attribute/subset evaluation class [evaluator options]">
    Sets attribute/subset evaluator.
    eg. -E "weka.attributeSelection.CfsSubsetEval -L"

Options specific to evaluator weka.attributeSelection.InfoGainAttributeEval:

-M
    treat missing values as a seperate value.
-B
    just binarize numeric attributes instead 
    of properly discretizing them.

Options specific to search weka.attributeSelection.Ranker:

-P <start set>
    Specify a starting set of attributes.
    Eg. 1,3,5-7.
    Any starting attributes specified are
    ignored during the ranking.
-T <threshold>
    Specify a theshold by which attributes
    may be discarded from the ranking.
-N <num to select>
    Specify number of attributes to select

General options:

-h
    Get help on available options.
    (use -b -h for help on batch mode.)
-i <file>
    The name of the file containing input instances.
    If not supplied then instances will be read from stdin.
-o <file>
    The name of the file output instances will be written to.
    If not supplied then instances will be written to stdout.
-c <class index>
    The number of the attribute to use as the class.
    "first" and "last" are also valid entries.
    If not supplied then no class is assigned.

我环顾四周,似乎找不到任何可以解决我问题的东西。

4

1 回答 1

0

这真的是一个救命稻草,但你有没有尝试过类似的东西

var="$(java GetFilter $WandFDir)"
java -cp $wekaPath $var -i $(pwd)/temp/training"$i"_$arffName.arff -o $(pwd)/temp/training_"$i"_$arffName.arff
于 2013-04-10T19:39:38.277 回答