From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 22889 invoked from network); 6 Jun 2020 18:20:34 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 6 Jun 2020 18:20:34 -0000 Received: (qmail 13866 invoked by alias); 6 Jun 2020 18:20:21 -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: List-Unsubscribe: X-Seq: 24908 Received: (qmail 14400 invoked by uid 1010); 6 Jun 2020 18:20:21 -0000 X-Qmail-Scanner-Diagnostics: from mail-oi1-f182.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25828. spamassassin: 3.4.4. Clear:RC:0(209.85.167.182):SA:0(-1.9/5.0):. Processed in 1.722891 secs); 06 Jun 2020 18:20:21 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.167.182 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UKfSvDDzNjzCYaEZR1LuLsGQssjKG8OkKzr5OFkjr4s=; b=IyTA6o0NW0f1VxoMTi+T2gSYvi76KFnv5qaRPjSH0mtm1X3jFDz6K4diwX2fs6QArX IfYLlEUcdAlyNySDmNErW0l3myTs0lcV0PKZ8gxA/RV6XL6lblbJRu8E2cSdlAvETqON aF4b0DdgyppwQqFivumKepgQXjnKrwQOzQLHZ9k7JQZT9Wa7gMHophydxaXaF71reE4y /A2KsEhqdZ4fNexfspMaBpSUmIMIQvZuP3EymKBd/mH2/28WZP7MpPblM/j24bk7wCGw x18f9Qned5uaAwqZPyjemZ7nvjBYMSBqn+WnLcv1uxtnx4pTE6aBxMkCXClKaEIv1Ep1 iRGw== X-Gm-Message-State: AOAM53387DMjMXOIFDyu5GNvm7FLQYZ/zvYGGzyp8NEYdQ18ki79XwIe 6nksdAVr1rVjN0nVMQlM5SOAmcgddN0tZ+vQevqoDQ== X-Google-Smtp-Source: ABdhPJw7CYLK/mcPd2R6To4OUT6i+tciN+IWcWhbhc1zupTzH3hH88hg7CLojUQ/JTDjJl+gA+hebycdnqok4tAIzQs= X-Received: by 2002:aca:1b13:: with SMTP id b19mr2368937oib.132.1591467585751; Sat, 06 Jun 2020 11:19:45 -0700 (PDT) MIME-Version: 1.0 References: <20200606010018.5d9c4a33@tarpaulin.shahaf.local2> In-Reply-To: <20200606010018.5d9c4a33@tarpaulin.shahaf.local2> From: Bart Schaefer Date: Sat, 6 Jun 2020 11:19:34 -0700 Message-ID: Subject: Re: subprocess To: Daniel Shahaf Cc: Mikael Magnusson , Pier Paolo Grassi , Zsh-Users List Content-Type: text/plain; charset="UTF-8" On Fri, Jun 5, 2020 at 6:01 PM Daniel Shahaf wrote: > > On 6/5/20, Pier Paolo Grassi wrote: > > > efe() cat $1 > > > efe <(seq 1 10) | wc -l > > > cat: /proc/self/fd/13: No such file or directory > > > 0 > > > > > > gives error, instead these all works fine: > > > efe =(seq 1 10)| wc -l > > > cat <(seq 1 10)| wc -l > > And this, > > % () { cat $1 } <(seq 1 10) | wc -l You can see what's happening if you do it this way: % efe() ls -l ${${1:+$1:h}:-/proc/self/fd} % efe <(seq 1 10) | cat total 0 lrwx------ 1 schaefer schaefer 64 Jun 6 10:59 0 -> /dev/pts/0 l-wx------ 1 schaefer schaefer 64 Jun 6 10:59 1 -> pipe:[1945962] lrwx------ 1 schaefer schaefer 64 Jun 6 10:59 2 -> /dev/pts/0 lr-x------ 1 schaefer schaefer 64 Jun 6 10:59 3 -> /proc/5533/fd % () { ls -l $1:h } <(seq 1 10) | cat total 0 lrwx------ 1 schaefer schaefer 64 Jun 6 11:00 0 -> /dev/pts/0 l-wx------ 1 schaefer schaefer 64 Jun 6 11:00 1 -> pipe:[1945988] lr-x------ 1 schaefer schaefer 64 Jun 6 11:00 11 -> pipe:[1944505] lrwx------ 1 schaefer schaefer 64 Jun 6 11:00 2 -> /dev/pts/0 lr-x------ 1 schaefer schaefer 64 Jun 6 11:00 3 -> /proc/5537/fd A named function on the left side of a pipeline becomes its own "job", where all descriptors above 10 are closed. An anonymous function stays in the parent shell (which is still a forked subshell, because of the pipeline) so those descriptors are not closed. % efe =(seq 1 10) | cat total 4 -rw------- 1 schaefer schaefer 21 Jun 6 11:09 zshkDpnRj In that case a real file has been created and is referenced by name, so the descriptors closing does not matter. % efe <<(seq 1 10) | cat total 0 lr-x------ 1 schaefer schaefer 64 Jun 6 11:13 0 -> pipe:[1946804] l-wx------ 1 schaefer schaefer 64 Jun 6 11:13 1 -> pipe:[1946579] lrwx------ 1 schaefer schaefer 64 Jun 6 11:13 2 -> /dev/pts/0 lr-x------ 1 schaefer schaefer 64 Jun 6 11:13 3 -> /proc/5599/fd For <<(...) no file is created at all, instead the standard input of the function is changed. > Mikael Magnusson wrote on Fri, 05 Jun 2020 12:25 +0200: > > > > This also works, > > % efe <(seq 1 10) > >(wc -l) > > as does this, > > % wc -l < <(efe <(seq 1 10)) In both of these cases, there is no pipeline, so efe stays in the parent shell and all the descriptors remain open.