This is a test version of Biostars. For the public version, visit https://www.biostars.org.
shell --- while

when I do something like this,I got a question:

yi@yi:~$ cat ids.txt
CDS
chromosome
exon
five_prime_UTR
gene
mRNA
scaffold
three_prime_UTR

# this way has a result
yi@yi:~$ while read line; do arr1[++i]=$line;done < ids.txt
yi@yi:~$ echo ${arr1[@]}
CDS chromosome exon five_prime_UTR gene mRNA scaffold three_prime_UTR

# but this one -- nothing!!!
yi@yi:~$ cat ids.txt | while read line;do arr2[++i]=$line;done
yi@yi:~$ echo ${arr2[@]}

yi@yi:~$

why!!!!

shell

1 answer

This should answer you question:

https://stackoverflow.com/questions/4642191/read-line-by-line-in-bash-script

Essentially, when you do piping |, you want read CMD instead of read line

Log in to answer this question.