使用Shell脚本运行Jar

时间:2016-06-20 22:16:07

标签: bash shell

所以我有一个Java文件,需要运行以下字符串。

java --classpath=$CLASSPATH:/path/to/jradius-client.jar net.sourceforge.jradiusclient.TestRadiusClient hostname authport acctport shared-secret username password

我需要做的是编写一个脚本,该脚本使用某个textFile.txt中与空格分隔的单词,并使用每个单词代替shared-secret。如果成功,请打印单词。

我到现在所拥有的是:

#!/bin/bash

java --classpath=$CLASSPATH:/path/to/jradius-client.jar net.sourceforge.jradiusclient.TestRadiusClient "val" 1812 1813 shared-secret username password

exit $?

我想要的是这样的东西(在Java中像伪代码,我没有bash经验:():

String s = Words From Text File As String
String[] words = s.split("\\W+");
for(word : words){
    try and run The JAva .jar File With Params X, Y, word, Z
        success? print word
}

我怎样才能做到这一点? 感谢。

1 个答案:

答案 0 :(得分:1)

https://stackoverflow.com/a/7721320/2193968

获取循环的想法
for word in $(<textFile.txt)
do
    java --classpath=$CLASSPATH:/path/to/jradius-client.jar net.sourceforge.jradiusclient.TestRadiusClient hostname authport acctport $word username password
done

这将读取textfile.txt中每一行的每个单词并将其放入word,然后运行命令将$word替换为从文件中读取的值。

相关问题