jQuery in Action, 2nd edition*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "done &lt; $1?" Watch "done &lt; $1?" New topic

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"
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29220

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.

I agree. Here's the link: http://aspose.com/file-tools
subject: done &lt; $1?
Similar Threads
Execute String as a Unix Command
How to read one file and replace contents in another file
error starting up 2nd instance of tomcat
Making multiple files from single file
Tomcat fails to restart with "Address already in use" exception