0

I have a command that I would like use two variables in and am having issues. How can I setup a for loop that will start with the first line in both lists and work its way through the entire list for each loop? I tried something like below without any success.

thank you in advance for any help you can provide

#!/bin/bash

i=$(cat list1.txt)
j=$(cat list2.txt)
for i in ${i}: for i in ${j}
        do
    python ggsashimi.py -b 1A_filtered.bam -c ${i} -g /gencode.v38.annotation.gtf -o ggsashimi/${j} samples -M 10 -C 3 -O 3 -A median --alpha 1 -F tiff -R 350 --base-size=16 --shrink --height=5 --width=18 --fix-y-scale
        done
Patchhr33
  • 3
  • 2
  • This might help: `i=($(< list1.txt)); j=($(< list2.txt)); for ((x=0; x<${#i[@]}; x++ )); do echo "${i[$x]} ${j[$x]}"; done` – Cyrus Nov 14 '22 at 22:05
  • Please clarify what you mean by "work its way through the entire list for each loop". For instance, if list1.txt contained "A", "B", and "C", and list2.txt contained "X", "Y", and "Z", do you want the loop to run with "A", "B", and "C", "X", "Y", "Z"; or with "A" and "X", "A" and "Y", "A" and "Z", "B" and "X", ...; or do you want it to run with "A" and "X", "B" and "Y", "C" and "Z"; or something else? – Gordon Davisson Nov 14 '22 at 22:07
  • Which shell, **specifically**? sh, or zsh, or bash? They're all different; tag for only one at a time. – Charles Duffy Nov 15 '22 at 00:19
  • Neither sh, nor zsh, nor bash have a "multiple variable loop", and your code wouldn't make sense in any of those. Unless you **have** to use `sh`, my recommendation in bash and in zsh would be to make `i` and `j` an **array** and have one loop where the loop variable is an array index. Don't forget to catch the case that your two arrays are not of the same size!! – user1934428 Nov 15 '22 at 07:43
  • The linked duplicate says nothing about the the preferred method for reading from two files in lockstep, which would be something like `while read i <&3 && read j <&4; do ...; done 3< list1.txt 4< list2.txt`. – chepner Nov 20 '22 at 00:06

0 Answers0