Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15017 > unrolled thread

Re: Reading from a file by using its FD returns its contents only once

Started bymike b <michallinuxstuff@gmail.com>
First post2018-12-31 18:19 +0100
Last post2018-12-31 18:19 +0100
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Reading from a file by using its FD returns its contents only once mike b <michallinuxstuff@gmail.com> - 2018-12-31 18:19 +0100

#15017 — Re: Reading from a file by using its FD returns its contents only once

Frommike b <michallinuxstuff@gmail.com>
Date2018-12-31 18:19 +0100
SubjectRe: Reading from a file by using its FD returns its contents only once
Message-ID<mailman.6627.1546276767.1284.bug-bash@gnu.org>
That's a good point, I haven't thought about it like this. I always thought
that each read always starts at the beginning of the file given fd points
at. So the fact that it changes offset is a bit surprising:

# echo word >t
# exec {in}<t
# read -rn1 -u"$in"; echo "$REPLY"
w
# read -rn1 -u"$in"; echo "$REPLY"
o
# read -rn1 -u"$in"; echo "$REPLY"
r
# read -rn1 -u"$in"; echo "$REPLY"
d

I mean, it's surprising to me, I am not saying it's bad behavior or
anything.

Anyways, thanks for your feedback Tadeus. :)

pon., 31 gru 2018 o 17:40 Tadeus Prastowo <tadeus.prastowo@unitn.it>
napisaƂ(a):

> On Mon, Dec 31, 2018 at 2:37 AM mike b <michallinuxstuff@gmail.com> wrote:
>
> [...]
>
> > The above is just an example. Doing reads on any other regular file like
> > this yields same behavior:
> > # echo bla >./t
> > # exec 10<./t
> > # read -r <&10
> > # echo $REPLY
> > bla
> > # read -r <&10
> > # echo $REPLY
>
> That's correct behavior because the second `read -r' already hits an
> EOF, isn't that?
>
> --
> Best regards,
> Tadeus
>

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web