New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Apps and Games Discussion of applications and games available for Mac OS X.

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


Post Reply New Thread Subscribe

 
Thread Tools
Straitsfan

 
Member Since: Feb 03, 2008
Posts: 142
Straitsfan is on a distinguished road

Straitsfan is offline
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.
QUOTE Thanks

Post Reply New Thread Subscribe


« iCal alarms aren't working :( | Safari - Displaying every website I want, except one??? »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Show Item Info inflexion OS X - Operating System 15 10-24-2005 10:34 PM
Shell script question Niwrad OS X - Development and Darwin 14 06-28-2005 04:58 PM
Terminal Help rs2sensen OS X - Apps and Games 1 04-25-2005 10:52 PM
Shell Script on Desktop starrin OS X - Operating System 2 07-28-2004 11:25 AM
looking for a terminal emulator and command shell in Mac OSX CandiMarie OS X - Operating System 9 03-05-2004 03:53 PM

All times are GMT -4. The time now is 12:21 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?