I want to extract a list of sequences from NCBI. I am esearch command mentioned [here][1]. For one gene symbol, I could do it like this:

    esearch -db nuccore -q 'SS1G_01676[gene]' | efilter -source refseq -molecule genomic | efetch -format gene_fasta |  awk -v RS='(^|\n)>' '/SS1G_01676/{print RT $0}'

I want to use a bash loop to extract a list of sequences and below is what I have tried, but wouldn't yield any results. What am I missing here?

    declare -a arr=("SS1G_03709" "SS1G_07286" "SS1G_04907")
    for i in "${arr[@]}"
    do
    myquery="'${i}[gene]'"
    echo "myid :" ${i}
    echo "my query :" ${myquery}
    esearch -db nuccore -q ${myquery} | efilter -source refseq -molecule genomic | efetch -format gene_fasta |  awk -v RS='(^|\n)>' '/${i}/{print RT $0}' >>text.fasta
    done

  [1]: https://www.biostars.org/p/345772/#345918
You are right, it stops after the first gene. I am not sure why. (EDIT: see explanation below) This works though:

    for line in `cat temp.txt`; do esearch -db nuccore -q $line| efilter -source refseq -molecule genomic | efetch -format gene_fasta | awk -v r="$line"  'BEGIN {RS="(^|\n)>"} $0 ~ r {print ">" $0}'  ; done

Apparently, for while loops involving `esearch` one should add `< /dev/null` to prevent esearch from "draining" the remaining lines from stdin. See documentation here: https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.While_Loop