From owner-freebsd-bugs@FreeBSD.ORG Mon Apr 9 01:00:34 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE2B0106566B for ; Mon, 9 Apr 2012 01:00:34 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 7D7338FC0C for ; Mon, 9 Apr 2012 01:00:34 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3910YM9043549 for ; Mon, 9 Apr 2012 01:00:34 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q3910Y4w043546; Mon, 9 Apr 2012 01:00:34 GMT (envelope-from gnats) Resent-Date: Mon, 9 Apr 2012 01:00:34 GMT Resent-Message-Id: <201204090100.q3910Y4w043546@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jim Pryor Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F1DCB106564A for ; Mon, 9 Apr 2012 00:52:04 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id DDF388FC0A for ; Mon, 9 Apr 2012 00:52:04 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q390q4MX036034 for ; Mon, 9 Apr 2012 00:52:04 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q390q4PA036033; Mon, 9 Apr 2012 00:52:04 GMT (envelope-from nobody) Message-Id: <201204090052.q390q4PA036033@red.freebsd.org> Date: Mon, 9 Apr 2012 00:52:04 GMT From: Jim Pryor To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/166771: In sh, "local var=$(cat)" only reads one line X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Apr 2012 01:00:34 -0000 >Number: 166771 >Category: bin >Synopsis: In sh, "local var=$(cat)" only reads one line >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 09 01:00:34 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Jim Pryor >Release: 9.0-PRELEASE >Organization: >Environment: FreeBSD vaio.jimpryor.net 9.0-PRERELEASE FreeBSD 9.0-PRERELEASE #0: Tue Nov 29 02:45:33 EST 2011 root@vaio.jimpryor.net:/usr/obj/usr/src/sys/MINE amd64 >Description: I notice the following issue in FreeBSD's /bin/sh, here's the version line from the source: * $FreeBSD: src/bin/sh/shell.h,v 1.22.2.1 2011/09/23 00:51:37 kensmith Exp $ Inside a function, a statement of the form: local VAR=$(cat) will only consume the first line of stdin. The same problem also afflicts a recent build of dash on Linux, but not Busybox's implementation of ash. Also reported here: . >How-To-Repeat: #!/bin/sh test1() { local IN=$(cat) printf "test1 <%s>\n" "$IN" } test1a() { local IN IN=$(cat) printf "test1a <%s>\n" "$IN" } test2() { local IN="$(cat)" printf "test2 <%s>\n" "$IN" } test3() { IN=$(cat) printf "test3 <%s>\n" "$IN" } test4() { IN="$(cat)" printf "test4 <%s>\n" "$IN" } MSG=$(printf "abc\ndef\nghi") printf "%s" "$MSG" | test1 printf "%s" "$MSG" | test1a printf "%s" "$MSG" | test2 printf "%s" "$MSG" | test3 unset IN printf "%s" "$MSG" | test4 # The weird bit only shows up in test1: # IN will only be assigned the first line of stdin. >Fix: >Release-Note: >Audit-Trail: >Unformatted: