File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
author & internet detective

Joined: May 26, 2003
Posts: 33129

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, 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:
subject: done &lt; $1?
It's not a secret anymore!