This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes done < $1? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "done &lt; $1?" Watch "done &lt; $1?" New topic
Author

done &lt; $1?

Joe Allen
Ranch Hand

Joined: Nov 14, 2012
Posts: 93


I am confused with "done < $1". If taking away "< $1", would the code still work properly? Could anyone please explain this to me? Thanks.

"There are no dumb questions" quoted from HFSJ. "To err is human; to forgive is divine"
OCPJP 6, OCEJWCD 6
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

Joe,
In UNIX, the idiom to read a file is:

while read line; do
# code to do work
done < fileToRead

In your example, the code has abstracted "fileToRead" into a variable that is passed at the command line. That's what $1 is. The program won't work without < $1 because UNIX won't know what lines to read.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Joe Allen
Ranch Hand

Joined: Nov 14, 2012
Posts: 93
Hi Jeanne,

It is nice to see you are in this forum too. Thank you so much for the explanation.

Joe
 
 
subject: done &lt; $1?
 
Similar Threads
Tomcat fails to restart with "Address already in use" exception
Execute String as a Unix Command
Making multiple files from single file
How to read one file and replace contents in another file
error starting up 2nd instance of tomcat