- 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:
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.
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.