From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13100 invoked by alias); 11 Apr 2011 17:33:38 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15957 Received: (qmail 23072 invoked from network); 11 Apr 2011 17:33:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.215.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=af1erM1mL+7YMMnBltfW9Foze9iOKYr05YCTjtlWKVA=; b=NYVYQC9bRJnuha/0e0tpOAkOlje/iBm/PB46lghgqVhwkV2ytnaQrFz7Y+sr5XGwIy NyOVB4zKlrtZvx6W2rYtSZz+rBSk/yvDWFAdZ6mi7rJEmur5ggEK0dnj22b6YQFHSkzQ DLmBVwUBSQeTa1tgMJOIi6CRek3sglZiYfysA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=j1E7pjABHWNZFI9Dx5viEqavoC0/ehgetIKfMcBldKgw6AawFs7kjlNzzsaz4cyg4w CRhKOCaVBcP+yX5cq9KHg5QHBgr2rKAiG8iYu2iX/SQuwNRScm8R8RyZ0CxdHjlq04Jv Lk24TIjvjiP/5S/knjz27OpOLTfR0PHLHD+U8= MIME-Version: 1.0 In-Reply-To: <20110411174825.3bd3e84b@pwslap01u.europe.root.pri> References: <20110411173835.385fba1f@pwslap01u.europe.root.pri> <20110411174825.3bd3e84b@pwslap01u.europe.root.pri> From: =?UTF-8?B?SsOpcsOpbWllIFJvcXVldA==?= Date: Mon, 11 Apr 2011 19:33:05 +0200 Message-ID: Subject: Re: $pipestatus and shell functions To: Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Peter, 2011/4/11 Peter Stephenson : > On Mon, 11 Apr 2011 17:38:35 +0100 > Peter Stephenson wrote: >> J=C3=A9r=C3=A9mie Roquet wrote: >> > $ foo() { false | true } >> > $ true | foo ; echo $pipestatus >> > 1 0 >> >> You're falling >> foul of (i) a shell function looks like a job to the shell (ii) it >> appears that function is being made the current job, so generates the >> pipe status when it exits (the same happens if you use a { ... } >> expression there, so that's not a workaround). =C2=A0However, there's so= me >> truly horrible handling for job control in complicated cases like >> this (what is supposed to get signals and what do you return to if >> you get one?) so it's quite possible that those two contributing >> factors are themselves deliberate. =C2=A0I'm not entirely convinced, >> though; it surprises me that that the notion of the current job >> changes like that. > > A little digging suggests it is deliberate. =C2=A0If you ever have a week= to > spare, look at the comment relating to the declaration of list_pipe in > exec.c. =C2=A0Within the description of the example: > > =C2=A0 =C2=A0cat foo | while read a; do grep $a bar; done > > you find > > =C2=A0 If the user hits ^Z at this point (and jobbing is used), the > =C2=A0 shell is notified that the grep was suspended. The list_pipe flag = is > =C2=A0 used to tell the execpline where it was waiting that it was in a p= ipeline > =C2=A0 with a shell construct at the end (which may also be a shell funct= ion or > =C2=A0 several other things). When zsh sees the suspended grep, it forks = to let > =C2=A0 the sub-shell execute the rest of the while loop. > > So the shell is deliberately treating constructs in the right hand side > of the pipeline as jobs in their own right, and in particular as the > current foreground job, since that's the one where you can do job > control. =C2=A0This overrides the natural expectation that the pipeline i= s > the current job and so the one for which $pipestatus would be reported. Makes sense for job control, but that's=E2=80=A6 counter intuitive for $pipestatus. I've to think a bit longer about it ;) Anyway, thanks a lot for your help, the subshell trick does the job. Best regards, --=20 J=C3=A9r=C3=A9mie