From owner-freebsd-hackers@FreeBSD.ORG Thu May 30 22:30:48 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 402E5413 for ; Thu, 30 May 2013 22:30:48 +0000 (UTC) (envelope-from jilles@stack.nl) Received: from mx1.stack.nl (unknown [IPv6:2001:610:1108:5012::107]) by mx1.freebsd.org (Postfix) with ESMTP id 07E57EEF for ; Thu, 30 May 2013 22:30:48 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id A285612013D; Fri, 31 May 2013 00:30:31 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 8900928493; Fri, 31 May 2013 00:30:31 +0200 (CEST) Date: Fri, 31 May 2013 00:30:31 +0200 From: Jilles Tjoelker To: =?iso-8859-1?Q?V=E1clav?= Zeman Subject: Re: /bin/sh => STDIN & functions, var scope messing Message-ID: <20130530223031.GA1672@stack.nl> References: <20130527.194235.693.1@DOMY-PC> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: rank1seeker@gmail.com, Reid Linnemann , hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 May 2013 22:30:48 -0000 On Tue, May 28, 2013 at 11:48:47AM +0200, Václav Zeman wrote: > On 27 May 2013 21:58, Reid Linnemann wrote: > > from SH(1) > > "Note that unlike some other shells, sh executes each process in a pipe- > > line with more than one command in a subshell environment and as a > > child > > of the sh process." > > I'm taking this to mean that redirecting to sh_f has sh_f execute in > > a subshell in which global_scope_var changes, but the original > > shell's copy is uncahnged. > Curious. Which of the two behaviours is POSIXly correct? Both. As per XCU 2.12 Shell Execution Environment, each command in a multi-command pipeline may or may not be executed in a subshell environment. Behaviour different from our sh is most often encountered in the various versions of the real Korn shell (ksh88 and ksh93), which execute the last command in a pipeline in the current shell environment. If things like jobs | cat work, that can also be explained using this rule. -- Jilles Tjoelker