別の 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 プログラムが実行されるからです。エコーせずにシェルスクリプトから実行しようとすると問題が発生し、ターミナルから次のようになります。
<!-- 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)
シェル スクリプトでの出力をハード コードすると、次のようになります。
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.
私は周りを見回しましたが、私の問題を解決するものは何も見つからないようです。