简体   繁体   English

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

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

I have a shell script that executes a Java program with parameters returned from a different Java program. 我有一个Shell脚本,该脚本使用从其他Java程序返回的参数来执行Java程序。

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

When echoed, it produces the following string: 回显时,它将产生以下字符串:

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

Which is great, because if I copy the string to the command line, it runs the Java program without incident. 很棒,因为如果我将字符串复制到命令行,它将运行Java程序而不会发生任何事件。 The problem arises when I don't echo it and try to execute it from the shell script, and I get the following from the terminal: 当我不回显它并尝试从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.

When I hard code the output of $(java GetFilter $WandFDir) in the shell script: 当我在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

It also runs without incident. 它也可以正常运行。 Interestingly though, when echoed, the double quotes disappear. 有趣的是,双回声消失了。

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

When I leave the double quotes out of the output of $(java GetFilter $WandFDir) I get the following error: 当我在$(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.

I've looked around, and can't seem to find anything that solves my problem. 我环顾四周,似乎找不到能解决我问题的任何东西。

It's really a catch at the straw, but did you try something like 这真的很容易,但是您是否尝试过类似的方法

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