The bash script is supposed to do one and one thing; ie; feeding the list of file names one after the other separated by a space to the jar file.
Here is part of the script
for(i=1;i<=5;i++) do
java <myjar.jar>file$i
done
what i expect the java <myjar.jar> file$i
line to look like while executing the script is
java <myjar.jar> file1 file2 file3 file4 file开发者_开发技巧5
any help? Thanks!
Since it's bash, just do this:
java <myjar.jar> file{1..5}
One way to do this might be to leverage the automatic shell filename expansion:
java myjar.jar file[1-5]
The above assumes that the files exist in the filesystem beforehand. Or, you can do something like:
java myjar.jar `for i in 1 2 3 4 5; do echo file$i; done`
If you have a large number of items, the seq
command will help:
java myjar.jar `for i in $(seq 500); do echo file$i; done`
#!/bin/bash
declare -a listn
for n in $(seq $2 $3) ; do
listn=("${listn[@]}" $n)
done
java "$1" "${listn[@]}"
And call the script with three arguments:
./the_script myjar.jar 1 5
The first argument is your jar name, the next is the first number in your sequence, the last is the final number.
精彩评论