Forums Register Login

done < $1?

+Pie Number of slices to send: Send


I am confused with "done < $1". If taking away "< $1", would the code still work properly? Could anyone please explain this to me? Thanks.
1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Hi Jeanne,

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

Joe
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2325 times.
Similar Threads
Tomcat fails to restart with "Address already in use" exception
How to read one file and replace contents in another file
Execute String as a Unix Command
error starting up 2nd instance of tomcat
Making multiple files from single file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:17:11.