I am running a Java program through a bash script. My plan is to iterate over a for-loop to create the argument to pass:
lastLine=$(cat $info_file | wc -l)
countID=0
cat $info_file | while read fileID; do
initVar="${initVar} ${fileID}.txt"
countID=$(($countID + 1))
if [ "$countID" == "$lastLine" ]; then
echo $initVar > tmp_${SampleID}.txt
fi
done
InputListVar=$(cat tmp_${SampleID}.txt)
java ProgramX --input "${InputListVar[@]}" --output $output_file
However, when I run the script above I get the following message:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in path at index 15
I suppose that this is due to the space in the list of files I provide within the InputListVar array (as suggested here Illegal character in path at index 16). How could I solve this issue?
I don't work with
javabut I'm assumingjavawants to see something like:OP's script should generate this format IF
InputListVaris defined as an array, but it's not. The following creates a scalar variable:If we assume the following contents of the input file:
Then we get the following:
So when this is fed to
javathe following happens:NOTE:
${InputListVar}is technically the same as${InputListVar[0]}so OP's${InputListVar[@]}becomes${InputListVar[0]}which becomes${InputList}We can 'fix' the issue by insuring we're working with an array:
Back to the
javacall: