Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Apple Computing Products:
macOS - Apps and Programs
Terminal -- shell script -- script will only read two lines of a file
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Straitsfan" data-source="post: 1178118" data-attributes="member: 47577"><p>I'm learning about the read command and wrote this little script to read data from a file:</p><p></p><p>[CODE]</p><p>readfile()</p><p>{</p><p> while read variable; do</p><p>echo $variable</p><p>done</p><p>} </p><p>readfile < File.txt</p><p>[/CODE]</p><p></p><p>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?</p><p></p><p>Also, what does the statment</p><p></p><p>if [ $variable ] mean? Does it mean 'if the value of variable exists....'?</p><p></p><p>File.txt only consists of the words red, blue and green.</p></blockquote><p></p>
[QUOTE="Straitsfan, post: 1178118, member: 47577"] 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 [/CODE] 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]
Verification
Post reply
Forums
Apple Computing Products:
macOS - Apps and Programs
Terminal -- shell script -- script will only read two lines of a file
Top