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=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19546 invoked from network); 28 Jan 2021 00:00:08 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 28 Jan 2021 00:00:08 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611792009; b=sn0MjEVcbXB/sJVSHnS1vvaHW7AgQE1PCcnQ7aWyBAvFWdT709X+3Hem8bkINf9moBDIon4sPy x8V3U+uyr92LQ0WgT2GYaY0tmCgZoMSL8ldDpsVyL7FdQ083VtJGZBg3cusQP/BT4fVjDs52jh xq7pM8i3ltDMn9X2oXrzCPgSwW/drANl1AifDzFppoOtLoNr0TzWLUCzkiueTZzsEgHITA7PMR nqZMFXjgBqqr2h/RAeaIE6cBHAXUzjMUqS+0NuuRaNrxQERPVOv8A6tcG5mC4nDi17K+m01NxU Ph9Yx15tis/u9r/JcLIGCc7l19kZRD6P2+GwjhPbx0HOtQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f44.google.com) smtp.remote-ip=209.85.210.44; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1611792009; bh=JGaT4Ypdo6RoCPS2BMolcRzffuzMQ/XsmMap1zkIZzM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=WMbK08BALUdaS60FXopLn6PN8xuMGu9bTpy+8gqlXSxSgJDqvzIIH0YXbh4FMCkFBPObz9YkV8 O26tnR/RSD+8t1HT4P8NNJCR3ySJUhjl0kQFq8f8etcHw2WlNkoTyuLIqK8oM71apAudfDsiI4 v3PB/Urp/vb/oav9rxWZAnvqaSBoedrLPJMHoa4Q45aU+Tbyji9L2fo8C2zX1WRGFZyWYsR/nL KDdyMtzoLFb1WjdCw82+dw1mx8//bqTzA7X9H5/02bNib0Vp4BHkaZP6C3cvLRHKisHZe1Ee5Q oF/rA6lG6D/f1Fv4M//ofX2VmiBzYWyyXiVdcwE+dUtdZg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=oDh0hbyF4NGPAUewLi4WMNEBSoOlCI1OERLQ+g0rfq8=; b=d3wijnVbk5as9mcv88EspjvEbE fKcu9xw0Qu9iKFR/cVPwSRiU6RVzTvAWW39aihJA0BkZgRF+CLK7xSqbNL/FWb4Nb7pGZT+8OIkDO Owha47YcIOBD+qlVt4g2ZTC5QNOGRQ8RZpbGZv8WkUSwbRnELtuMx2a1yK/w/DQdDB5GyF7xFv460 ODy7yrmGfCZxkj2aWzZVWPJME1AR9+EsuFSxHIRKuzSHv4O+YRh9DNTrY7WkgrvpMCkvNgPyvJIzz cGyLSTbq/fzPhwoSw8Ek26IRhom19DNiDnGt0lWF7pml8eMhsgouyFK6DObKGMZvGPn5acwrw1lJZ 66xyulug==; Received: from authenticated user by zero.zsh.org with local id 1l4ujF-000CrA-9h; Thu, 28 Jan 2021 00:00:05 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f44.google.com) smtp.remote-ip=209.85.210.44; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ot1-f44.google.com ([209.85.210.44]:37846) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l4uij-000CRX-Bb; Wed, 27 Jan 2021 23:59:34 +0000 Received: by mail-ot1-f44.google.com with SMTP id h14so3536969otr.4 for ; Wed, 27 Jan 2021 15:59:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oDh0hbyF4NGPAUewLi4WMNEBSoOlCI1OERLQ+g0rfq8=; b=XpuJzDYzxt0s5ZYSrU95zRKsjUheDoSyMeXSvcYifEwZqVPQ9346EdehYcvoTVjrer WzLu4SfybinYmUu1rHsOJZUHlfEOxojihnP8k6ZPDvSQzZ/BIkGyutdqponnhvrp6Umv io3Ydh0+x/KYRDWlDHVwqJVQDnDtRN8uBdR50zBVPI5dxoUym/R2DzETl9WB4VyRREtW kRc/qTTlwx2tA7eY8NcFWVlNkAZaZeUJaG24GvSniDb6w7Zy1lvCh2l1ajpuGnbtGZTE 1ZQ62p7tCJm+NYrD+3ZTF1s0TL+pQg5QY7LydKDMvCKkra7yTiLIi65TGFTjx1n1wAc6 SqWA== 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=oDh0hbyF4NGPAUewLi4WMNEBSoOlCI1OERLQ+g0rfq8=; b=EAlRSFK9VvwfRSCDMHGSacjeYe29h2yITfvLVdZoETcCI9JR8iKAzmSB/TcgO2Xb0a H8bfEseHELuWTDXGgbBTTb21VGcyVEDXF9Yr3f86wRL/CwbqY/Ihkf67xyIFe+T1D0wi fQg2KxbGPWcwOpWXQnvsbQPxCvHOfkb6sn+WauAP0XnFk+GaQ6YG7dDYmzbNsFxQGYGE l13fjwdxr1C5F7Xh7nxxlJnU4wz9vy3A5w06F5TKyXPrRj+moTxBgrGIzGus5yDMY9ZL x0aEQqniur+sAMy6icDRkKKtxd6kf4YbjYw4+fpr2y7xg+NOnxeSWJI7W+BhH9UCSkRJ WiAw== X-Gm-Message-State: AOAM5308Z1UpJXBc1F5lZfNoqAycA5RTJi/zXiT24EJmM7s7bKBH2hcv L0zFY0+z+O6PiV65XWKy9kZ/ikSlHmCYotvAz7CFTw== X-Google-Smtp-Source: ABdhPJzRwcajXNK3rwdz63LwBMDhk+X2icwP/ddAGtcZlWaPkwJka21OJDMF6lv4eDtpxY/NHARkUK47In9hUX5dYB8= X-Received: by 2002:a9d:6358:: with SMTP id y24mr9549611otk.229.1611791971761; Wed, 27 Jan 2021 15:59:31 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Wed, 27 Jan 2021 15:59:20 -0800 Message-ID: Subject: Re: detect pipe To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26422 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Wed, Jan 27, 2021 at 8:45 AM Ray Andrews wrote: > > I have a function that as used this test for piping quite reliably: > > if [ ! -t 0 ]; then > > ... but today it stopped working. [ -t 0 ] or [[ -t 0 ]] mean that the standard input is a terminal. It's quite possible for standard input to be neither a terminal (so [[ ! -t 0 ]] is true) nor a pipe. For example, redirection from a file or use of a here-document will both take the then-branch of "if [[ ! -t 0 ]]; then ... else ... fi". > there a better way? This is probably not strictly a zsh problem but the > randomness of it working intermittently suggests some time lag or delay A race condition would be unlikely to be a cause here. [[ -p /dev/fd/0 ]] would be a more reliable test, because of the way conditional expressions special case the prefix "/dev/fd/".