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.

Go to topic 45533

Return to index page 163
Return to index page 162
Return to index page 161
Return to index page 160
Return to index page 159
Return to index page 158
Return to index page 157
Return to index page 156
Return to index page 155
Return to index page 154