Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create a file descriptor from within a script?

0 views
Skip to first unread message

Tobiah

unread,
Nov 19, 2009, 3:17:28 PM11/19/09
to
I have a friend that want to use 'read' to iterate
over the lines of a file:

while read -u 3 foo; do process $foo; done

Now this works, if the command line looks like this:

script 3< input_file

But he wants to set up the file descriptor within the script.
Can it be done? Is there another way to iterate over the
lines in a file using only bash?

Thanks,

Tobiah

Tobiah

unread,
Nov 19, 2009, 3:41:18 PM11/19/09
to
> But he wants to set up the file descriptor within the script. Can it be
> done?

I finally found a description of how to do this. The
answer is to use 'exec':

exec 3< file_name

creates a new descriptor which can be used with read.

read <&3 myline

0 new messages