Subject: bin/13883: sh: incorrect value of $? in here-documents
To: None <>
From: None <>
List: netbsd-bugs
Date: 09/06/2001 13:45:55
>Number:         13883
>Category:       bin
>Synopsis:       sh: incorrect value of $? in here-documents
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 06 13:47:00 PDT 2001
>Originator:     Matthias Pretzer
>Release:        1.5.1
NetBSD 1.5.1 NetBSD 1.5.1 (MYKERNEL) #1: Sun Sep  2 22:01:40 CEST 2001 i386
Bug found by Christian Weisgerber <> for FreeBSD. His description (taken from :

In here-documents, sh expands $? to the return value of the current
command rather than that of the previous command.

This behavior differs from that of all other Bourne family shells
I have tested (bash 2.05, ksh93 2001-07-04, pdksh 5.2.14, zsh 4.0.2,
Solaris 7 /usr/bin/sh and /usr/bin/ksh).

I noticed this because it breaks the evaluation of several
(non-critical) tests in the configure script of gtar 1.13.22.----

cat >>foo <<EOF
cat foo

Returns 0 for NetBSD sh, 1 for all other shells.