繁体   English   中英

在Shell脚本中执行Java程序时使用双引号

[英]use of double quotes when executing a java program in a shell script

我有一个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.

当我在shell脚本中对$(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.

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

这真的很容易,但是您是否尝试过类似的方法

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM