1

I would like to run a command in a bash script according to the following code sample. Despite the fact that j and i variables contain the filenames (these filenames were read out from the samples.list.txt), these strings can't be inserted into the command. What could be wrong? Many thanks!

cat work/sample.list.txt | while read line;
do
    arrIN=(${line// / })
    i=${arrIN[0]}
    j=${arrIN[1]}
    k=${arrIN[2]}

   java -jar some.jar ./input1directory/"$i" ./input2directory/"$j" 
done
10
  • What's you sample.list.txt contents? Commented May 11, 2015 at 9:41
  • currently only one line Commented May 11, 2015 at 9:44
  • control_0_D10_1.fq control_0_D10_2.fq control_0_D10 Commented May 11, 2015 at 9:44
  • 1
    What's the point of replacing space with space? Why not just arrIn=($line)? Commented May 11, 2015 at 9:47
  • 1
    Well, your default delimiter is ok. Please run your script as follows: bash -x ./yourscript.sh and post here the output. Thanks Commented May 11, 2015 at 10:20

1 Answer 1

4

You can read multiple variables at once, like this:

while read i j k ; do
   java -jar some.jar ./input1directory/"$i" ./input2directory/"$j" 
done < "work/sample.list.txt"

Every line read reads will get subject of word splitting and the individual fields will get assigned to the variables you specify on the command line. If there are more fields than variables, the whole remaining line gets assigned to that last variable specified.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.