From owner-freebsd-bugs Mon Aug 12 9: 0:14 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5CADD37B400 for ; Mon, 12 Aug 2002 09:00:08 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id F0A2043E42 for ; Mon, 12 Aug 2002 09:00:07 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7CG07JU050549 for ; Mon, 12 Aug 2002 09:00:07 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7CG070u050548; Mon, 12 Aug 2002 09:00:07 -0700 (PDT) Date: Mon, 12 Aug 2002 09:00:07 -0700 (PDT) Message-Id: <200208121600.g7CG070u050548@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Artem 'Zazoobr' Ignatjev" Subject: Re: bin/41410: /bin/sh bug on expanding $? in here-documents Reply-To: "Artem 'Zazoobr' Ignatjev" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/41410; it has been noted by GNATS. From: "Artem 'Zazoobr' Ignatjev" To: freebsd-gnats-submit@FreeBSD.org, rse@engelschall.com Cc: Subject: Re: bin/41410: /bin/sh bug on expanding $? in here-documents Date: Mon, 12 Aug 2002 19:52:55 +0400 I've hacked around a bit, and found following code : eval.c:649: oexitstatus = exitstatus; eval.c:650: exitstatus = 0; then, in function expredir: eval.c:454: for (redir = n ; redir ; redir = redir->nfile.next) { eval.c:455: struct arglist fn; eval.c:456: fn.lastp = &fn.list; eval.c:457: oexitstatus = exitstatus; But once we're here, exitstatus is already 0 I've tried to remove offending line #650, and your script showed the same values three times. I've also modified it to check, whether it's required to explicitly set exitstatus to 0, testing "yes" for being "yes" each time after your attempt. Output is as shown: attempt 1: $?=1 $1=foo $2=bar $baz=quux attempt 1': $?=0 $1=foo $2=bar $baz=quux attempt 2: $?=1 $1=foo $2=bar $baz=quux attempt 2': $?=0 $1=foo $2=bar $baz=quux attempt 3: $?=1 $1=foo $2=bar $baz=quux attempt 3': $?=0 $1=foo $2=bar $baz=quux Here's my version of your script: begin 644 buggy.sh.gz M'XL(`!#65ST``^W8OT[#,!`&\-U/<6TB4880DI:_:JB$!`M#7X#%"2:I%,?! M=B2*>'B<0EL52AL&!M!71;T,]SM_E]%>+RR4%*&=256%1F>A*=Q#S"-*FSR? M'YF",2,L!0$]*D4IURSE+\E3TSRSMHNXM4+6EKR(!F8FZU*0R`KENC5E2M9< MSXRJ#ID5QM)<&.HE;6&+IOY21Y=T[T\2?^)*E/B1*W'BQZZTI[5__?6$K0,. M.DS8#!R[P)*7)15"B^!!98T4E?V:-..6QN.;Z2U;TGCO6:QM_Y28OO^MS]C1 M]-&Z"K%_X_<4&TL/:5!RG8O-I>DJH='=]8[=Z95R+>KEH%6*X?X0QU$\')V< MGIU?_/P-&!@8&!@8&!@8&!@8&!CX_^(MUR<=[B(ZW(C\T>\!#`P,#`P,#`P, 4#`P,#`S\RWAQ&?$&0[*9Y"LC```` ` end And here's the suggested patch: --- /usr/src/bin/sh/eval.c Thu Jul 5 04:41:14 2001 +++ /usr/src/bin/sh/eval.c Mon Aug 12 19:29:00 2002 @@ -647,7 +647,7 @@ varflag = 1; oexitstatus = exitstatus; - exitstatus = 0; +// exitstatus = 0; for (argp = cmd->ncmd.args ; argp ; argp = argp->narg.next) { char *p = argp->narg.text; if (varflag && is_name(*p)) { --- Patch ends here --- Sinceherely yours, Artem 'Zazoobr' Ignatjev. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message