bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: mike b
Subject: Re: Reading from a file by using its FD returns its contents only once
Date: Mon, 31 Dec 2018 18:19:06 +0100

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 <address@hidden>
napisaƂ(a):

> On Mon, Dec 31, 2018 at 2:37 AM mike b <address@hidden> 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
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]