Terminal -- shell script -- script will only read two lines of a file

Joined
Feb 3, 2008
Messages
304
Reaction score
5
Points
18
I'm learning about the read command and wrote this little script to read data from a file:

Code:
readfile()
{
 while read variable; do
echo $variable
done
}    
readfile < File.txt

I have three lines in File.txt; each a single word. The script only echoes the first two lines and drops the third one. Can anyone tell me why?

Also, what does the statment

if [ $variable ] mean? Does it mean 'if the value of variable exists....'?

File.txt only consists of the words red, blue and green.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top