From owner-freebsd-questions Thu Jan 20 13:40:17 2000 Delivered-To: freebsd-questions@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 88E7415331 for ; Thu, 20 Jan 2000 13:40:12 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.9.3/8.9.3) id WAA05161; Thu, 20 Jan 2000 22:40:08 +0100 (CET) (envelope-from olli) Date: Thu, 20 Jan 2000 22:40:08 +0100 (CET) Message-Id: <200001202140.WAA05161@dorifer.heim3.tu-clausthal.de> From: Oliver Fromme To: freebsd-questions@FreeBSD.ORG, cjclark@home.com Reply-To: freebsd-questions@FreeBSD.ORG Subject: Re: sh(1) Messing with My Mind X-Newsgroups: list.freebsd-questions In-Reply-To: <867h6j$1kk4$1@atlantis.rz.tu-clausthal.de> User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (FreeBSD/3.4-19991219-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Crist J. Clark wrote in list.freebsd-questions: > [...] > seems to have muddled my thoughts this morning. Why does this happen: > > $ echo 3 | read NUM > $ echo $NUM > Because the read command is executed in a subshell when it is in a pipe. When the pipe ends, the subshell terminates, and its environment variables are gone. > [...] Why does it look like > read won't read from a piped stdin? It does read from the pipe, but the variable is only set in the subshell. It does not change the environment of the parent shell process. You usually solve this problem by using command substitution ("backticks"): NUM=`echo 3` Regards Oliver -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message