|
Subject:
|
Page 54: exec command rarely used?
|
|
Posted By:
|
buckersher
|
Post Date:
|
9/27/2006 9:56:44 AM
|
The author states:
exec 3< afile
This causes file descriptor three to be opened for reading from file afile. It's rarely used.
I disagree with the author's opinion that it is rarely used. Opening up a file for reading is a very common occurence. True, programmers will try to use more specific commands, such as grep, to find the specific variable they are looking for in a file, but I won't say that opening a file in order to read line after line is rare. As far as I know, I don't know of any other way to open a file for sequential reading besides using this command combined with the read command.
Here is real life example:
exec 3< $temp_file #read each line and make a directory for it while read -u 3 comp; do directory=$(echo $comp | tr -s '/') mkdir $main_dir$(echo $comp | tr -s '/') 2> /dev/null
This line of code opens up the file reading and then read each line creating a directory with the string on each line.
|
|