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!!!!
• 1,159 views
•
link
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
• 0 views
•
link
Log in to answer this question.