Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Oct 2018 15:30:40 +0300
From:      Yuri Pankov <yuripv@yuripv.net>
To:        Eugene Grosbein <eugen@grosbein.net>, Freebsd hackers list <freebsd-hackers@freebsd.org>
Subject:   Re: shell read built-in
Message-ID:  <4ad1ea37-4714-a104-89a2-d7aef70d0f89@yuripv.net>
In-Reply-To: <2fff355e-a729-d5d3-8199-f2bbba80c112@grosbein.net>
References:  <2fff355e-a729-d5d3-8199-f2bbba80c112@grosbein.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Eugene Grosbein wrote:
> Hi!
> 
> $ echo test | read line; echo $?
> 0
> $ echo -n test | read line; echo $?
> 1
> 
> Is it right behavior for /bin/sh?
> This makes it hard for "while read line ... < file"
> to process last line if it is not followed by new line character.

POSIX defines the exit status for read as (and sh(1) says the same):

    The following exit values shall be returned:
     0 Successful completion.
    >0 End-of-file was detected or an error occurred.

...and looks like all of /bin/sh, bash, ksh93 seem to agree on the
behavior here.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4ad1ea37-4714-a104-89a2-d7aef70d0f89>