From owner-freebsd-bugs@FreeBSD.ORG Tue Dec 20 13:40:08 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org 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 6775816A41F for ; Tue, 20 Dec 2005 13:40:08 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5ED1C43D5C for ; Tue, 20 Dec 2005 13:40:05 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id jBKDe5VY008928 for ; Tue, 20 Dec 2005 13:40:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id jBKDe5TW008927; Tue, 20 Dec 2005 13:40:05 GMT (envelope-from gnats) Date: Tue, 20 Dec 2005 13:40:05 GMT Message-Id: <200512201340.jBKDe5TW008927@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Oliver Fromme Cc: Subject: Re: bin/45584: read builtin function of sh does not read standard input X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Oliver Fromme List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Dec 2005 13:40:08 -0000 The following reply was made to PR bin/45584; it has been noted by GNATS. From: Oliver Fromme To: bug-followup@FreeBSD.org, Hideo.Kogoe@Sun.COM Cc: Subject: Re: bin/45584: read builtin function of sh does not read standard input Date: Tue, 20 Dec 2005 14:36:15 +0100 (CET) Hi, Actually it is well-known that parts of a pipeline are usually executed in sub-shells, so setting variables there has no effect. Scripts which try to do that are non-portable. In fact, most shells seem to use sub-shells: /bin/sh on FreeBSD, pdksh, bash, and even the /bin/sh on Solaris. I've found only two shells where "echo foo | read bar" works: zsh and Solaris' ksh. Therefore I think this PR should be closed. There are several workarounds. For simple cases, just use command substitution: $ line=`echo Hello` or: $ line=$(echo Hello) (The latter is preferred, because it is easier to nest and works better with qwoting.) For more complicated things, one possibility is to use a "here-document" with command substitution. See the sh(1) manpage for details. Example: This is not portable and does _not_ work: df -k / | awk '/%/{print $2, $3, $4}' | read a b c echo "Total disk blocks: $a" echo "Disk blocks used: $b" echo "Disk blocks avail: $c" Instead, the following works fine: read a b c <<-END $(df -k / | awk '/%/{print $2, $3, $4}') END echo "Total disk blocks: $a" echo "Disk blocks used: $b" echo "Disk blocks avail: $c" Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. "C++ is the only current language making COBOL look good." -- Bertrand Meyer