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 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21567 invoked from network); 8 Jan 2023 14:22:42 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Jan 2023 14:22:42 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1673187762; b=XvtFG/h8RsaTKVgHgpm3aYNixwOo0nHwOt6lm3jH/UP7YDu5I8/8+fd7f/OVe5JDFAKpkmrZsO PyL3Ua4vfKbwT3ZpeaafXIwbJxqF1ERtS6fj5+Gd0Z0ujmallbzDHstEqb71kBXc9t+qKE0ll8 rMME+TYNo3y1N87uoUWtMyGPt3S8pEjOVYTgNP9RRMGKaLf0cuu8XRO94AO6gJ6JWyuPmjxZqj J04T/2LijV1cVtjkv0zKL38TH7PwXx6hm3I3LPnDodvFF0ahVpxomOsVCqvyYle8p57FHvvMsU GSNjTk6MoWqSc+RVIgvBMJq1+PI2FdQjRfZ1B9HGXq7QPA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1673187762; bh=8u3CAv24lEFXNNb0Heu1nbvq6/+QPjflv5mnZe87Oo4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature:DKIM-Signature:DKIM-Signature; b=VtZ/IVq+gDn9V30zzr6zX/X/5JRyzQdb787Ic0XZOlU/Csa5YFWHvLEKrDEs4aNoW2NNoMTauT szvOyCs3pNCkCE0JgXyE89kreseviQp3OkKKQ+k7jSpHdaxLpn7VHfuPvJQcyy0Tv7ZoXL2cYA BYBLFPC2pGrAHFWMlnZDJft/Ootbc+F1KOKycjqud10ndDUo2UJbwMJ3fZR+QhoYGpN1MNPE0b +md8zKM6WEjcnRVsf5ctnf7Q/8RRyWcn60tUAT6jIqsRIIeWymWeQ1M/kSCqo6DNnaB1SYp+er IkKMLyLM6Lm1w11imtwQkOSlj5uHwo7t1bzszkP05HDCiw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=A5Jh2E3le9AwLAMblg6kLRnUlwVtZnn6lGPLbQH3cSI=; b=J4uXfNYjhtFkXSwH/Eap+CQEoe 69YO+qX8YSgT23jW5AoDeBruLvJMrmm7SA9IEP67oBK7EZmm+19t670hT1t4IltygLgpcJvZ3S8GM BuXolH8oRENQXSt1uDo14jHh5u96GDiwsKo3Xr0zgIhmDG/iWC/NXubUTYCz6j5MfgJJCyuyF6Wzt 5B3uG6TYcJhiw1TlyO3IcIHBn0Tb/MFWRyrcMZjRcTnwxzsM8aphwxOg6Lah3R+Hvf+vMGfC4RA+h y9hp/DN/rw8HCQOH4pz366D5uKXdS6mcgnKKtK20BGvZkv5CWH5i+iWCzHK2f+0sZKigp2AoU0nqd fVCMAwgg==; Received: by zero.zsh.org with local id 1pEWZM-0003Aj-K0; Sun, 08 Jan 2023 14:22:40 +0000 Authentication-Results: zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out5-smtp.messagingengine.com ([66.111.4.29]:48239) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1pEWYk-0002Tc-31; Sun, 08 Jan 2023 14:22:03 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 11CEE5C00AE; Sun, 8 Jan 2023 09:22:00 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 08 Jan 2023 09:22:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1673187720; x= 1673274120; bh=A5Jh2E3le9AwLAMblg6kLRnUlwVtZnn6lGPLbQH3cSI=; b=v ojOeIWHhp7xuuuXeCZSgsRCAbvdgiPZY2PP26M2gf5IWpek7OFUAfeWvDZVTRga7 zW7FOgNBoUDb8v0t5MCDCKNUK/o7bVAvYz6XxsWnpeqyDUXZu7VZxy+hjp9GTAmg Jc1f1xsZj/rckuajRE/Y3PJwUwFz1TmdrtI1dMb33DRLvB9VD8zLYNgVRMWwwkFK 12rgOl0v37NBl71phSERSg+11uFjgTLorosvmz637iMKc8vsOjUpBF6UK4z8CGUB 55DjZC2vJXtakFqU4P2kZBx3dxSi2GQVGhIM5nAMakVuexnb31P52IFXlOWJMcqX GONekCrG7fIuhhMFxI3jQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1673187720; x=1673274120; bh=A5Jh2E3le9AwLAMblg6kLRnUlwVt Znn6lGPLbQH3cSI=; b=Y60C1GdRTZxZT0k3GCaAl6lIXG41iWumQMAm3rmP0wcY fFTO2qis47xONONcZK10llHH7XoxRxMTfSYOwj0/VzBomFYNEvcJHb0VYwkegtCF ooYRIe8Fe9lTfvILJ3Scqxvr9ygXrFlRWknneL9loZuHexv1B9GCNlZKiYh4qYIq OH4SkZn7h8wumm4jG+0KUi43EnWoFzjusxzIXnYN9lMLu0TzVIvEurSWjHCKAjxc xk5PyaVj6aXp08GfTsAmuF5wZTrJbjM5TPkODZVilQf6OGG5MpM7SG6p1Bjr82/h UEyFl+5W/vPcTDUFriXXOSC1gmUZiuDYc0AzDjxWtw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrkeeggdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjfgesthdttddttdervdenucfhrhhomhepffgrnhhi vghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqne cuggftrfgrthhtvghrnhepgeffvefgvdfffeefleduhfejheektdejvdeileeutdekfeeg hfelkeekjedtgeetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i425e4195:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 8 Jan 2023 09:21:59 -0500 (EST) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4NqfQs5xkYz6k; Sun, 8 Jan 2023 14:21:57 +0000 (UTC) Date: Sun, 8 Jan 2023 14:21:57 +0000 From: Daniel Shahaf To: Zsh-Users List Cc: Pier Paolo Grassi Subject: Re: read with redirected stdin Message-ID: <20230108142157.GM8411@tarpaulin.shahaf.local2> References: <20230108132350.GL8411@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 28628 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: Roman Perepelitsa wrote on Sun, Jan 08, 2023 at 14:48:24 +0100: > On Sun, Jan 8, 2023 at 2:30 PM Daniel Shahaf wrote: > > > > Roman Perepelitsa wrote on Sat, Jan 07, 2023 at 18:31:30 +0100: > > > On Sat, Jan 7, 2023 at 6:22 PM Pier Paolo Grassi wrote: > > > > > > > > Thanks, but i don't _always_ redirect stdin. > > > > > > The code will still work (except for the corner case I mentioned). > > > > > > Upon further thinking, the following should work in all cases: > > > > > > if [[ -n $TTY ]]; then > > > # There is a terminal. Read from it. > > > read -k1 > > > else > > > # There is no terminal. Read from stdin. > > > read -k1 -u0 > > > fi > > > > Would it be useful to provide a ctermid(3) wrapper in zsh/system? > > Where would it be useful? In your code snippet quoted here? > Doesn't $TTY already provide a better alternative? $TTY could be unset or set to another value without affecting the controlling terminal. > IIRC, ctermid() always returns "/dev/tty" while $TTY points to the real device. On FreeBSD: % perl -wMstrict -MPOSIX=ctermid -E 'say ctermid' /dev/pts/0 That's when there is a controlling tty. Without one I do get "/dev/tty". You might be remembering GNU libc behaviour? Anyway, I suppose I should revise my point to 'Can we determine at the C level whether we have a controlling terminal more reliably than by checking $TTY, and if so, should we expose that to scripts'. Cheers, Daniel > Roman. >