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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30928 invoked from network); 7 Jan 2023 17:39:46 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Jan 2023 17:39:46 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1673113186; b=XGtLJECZUZTlRBkMZtvb166mPdf7JxoliyYB/hOxibRdZrwNQ5+V32Rl0qBJZwM0T5wA46MDuX VS7uBSkgv/0022WdNU6TARmm4BPx50oXALy0AlnV9EF8vPQwnuUEjEwN5C8PKghqTebRySI+oo T7JOtqe67dc/oHotBbD4lx0hhWs+tfX+6ijgAtDznTw/Bb6qGyhESW/+1I6bZrrCnz9w9UOASh myjPG+EtGZhqiCX/I9ciGyXsppXrClJvVzgw4FbqgfLIX3shFPFc9u4WvDWpmIYtbk8t5PDVsV 0RcaxckDBc8Qx33Q6NAilsj5V2ukkf/3yxTFQlIhIT8b8A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f42.google.com) smtp.remote-ip=209.85.208.42; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1673113186; bh=WMWqbauzIxmnBJzcn38zt/PklGw/N/FsZeziD9yyyjU=; 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=PJD473rg8aLG97I22JPnPjyRKR1OGVMFkpUi3rHjDucYkVKAMLvHMsSRhpAUWIt7Ri7sVImpJx k6Jv1tDFWU6AmuvoDPrgrxIOtguEBOBxPKB4TXrjmrJx5ak0pQdbvNdJKa6JR7azbvNDY9wm69 PPncz/tGZF75840mdE9dWzZxyJY7nJNJH1+DLFroi6nTmjlYgh0fYM1OCdkNY9gPMle5IErSzl IJqvhXlYeQNPd48VMEDvh8Dh0PshSQvyfZbLyx0/nW49Uwd3XPRXHPSMW1CLsYisoW0LCrVO39 OCCzeqxYkXebgSqYtaIFcg5vVi+6//AjD4G4yPsaGN70DA==; 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: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=QKGa22ssWOu9R8g4/kkICHdMAV/dDj+Z47MIgAtMN40=; b=nsTR3euZdXkSfQcbM2s2claZ3Z B3txmZh46NC0Pem4AHvjHu4h8xxLvbU28jgkK3FiXdM5w7EMQUE0QaXdMtsGkhmN5iAA38/5B6a1e 2kntaO8MX6bwajCVo2L4/5lB9W+L1qXKcowzYcaU9qPG7OD6u4jyNETFwqIJTOW03tF4Sg9uKTugF 0omKNcCDLTfa5cPpwK2ZOmy9s5wChyDgyCM5w3ffy7kZnxXQnccN4pXD+xIXJFLx7PYJjREgVZm2I XsdR92ElxBZAtnODZyjw2VVE/TnjMdhDtullsIHZEIbizuZ0IDDMkNea2vZjNRMA2SMYdtDdWk7eg c6qUTXMg==; Received: by zero.zsh.org with local id 1pEDAX-000IDO-No; Sat, 07 Jan 2023 17:39:45 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f42.google.com) smtp.remote-ip=209.85.208.42; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ed1-f42.google.com ([209.85.208.42]:45572) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pED8E-000HEC-FM; Sat, 07 Jan 2023 17:37:22 +0000 Received: by mail-ed1-f42.google.com with SMTP id s5so6439967edc.12 for ; Sat, 07 Jan 2023 09:37:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QKGa22ssWOu9R8g4/kkICHdMAV/dDj+Z47MIgAtMN40=; b=UI7rDO1FNJI0wxu8t6f9UX4lPDt9ysnwffZGCFAUWOFCv8uUaFMMuWegIOocWQTlHI 2X+Y6S8GYA05O6U6fdYSJePW3adUvryt1L/q2O36X998tJ+92Y4Akbz5PLFK1lNzxrMe 1T2Pt/y/++EexZBEc3dkiVrwpJBHWDSFteTkgN7zj9sZs4ppeAUAkzAVP0RWXlnHck9i RaCZJuRCbMy8WrOFxoigHeJvq1Rva8qTR59ytW+IVxwrTfNHYIybqn9Iq6WjC0EsO+cM Y5Hp/MEQ8KKntO+4lQkHv218JdkaOcmj+SCcAejGIWEzq2gXXNTARR/PA0Y0CRnP9STR AHOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QKGa22ssWOu9R8g4/kkICHdMAV/dDj+Z47MIgAtMN40=; b=rKWRaVuPwme2AdXx0Hx8UYRhdxfS4DWCyH8XT1Gr3GuL0sYQRKCaGXBQBJR+ZZuAO2 WQJpUnYQnIfVQ0WPAYDU2Rg70i3yH5jd5zJJjwh1rr80E9RJKKYVjM4Du+eXxc8gI5Og Ij5Ver8qF/cac5G8NydG9g6yelEUws26vGJqIJr8XPKH10DpMSYT9xyOunXxFTzN77FI v14wqdvlbvIV/HIseKpHuiRnqC65WlM/k5zGm8SAh2ccM1GOS65pNM624zaSAO6Wy2tF X00yVNxqBdZI8NTPwgD+Heuvj74ixrDFOyJOqPYLNUCFtbxTsmkEYY6roldMp1DB/JkR 8sKg== X-Gm-Message-State: AFqh2konil6RR3xd6VH89FUZqXqOswIuE0hTqY1b80xBR86HqEnX358M 5Cl2InqwvOcGbe3HVuMa1xCrKM/BeqQtNBh2Uejki9OerJE= X-Google-Smtp-Source: AMrXdXuRvNrFe4YVq6WsDppWT3sbFRkSqdtNApc05A7VqUp9Qc6rwnQhIAJKtgeWJckHZWkLuT2L+45SZqJwO/y80T0= X-Received: by 2002:a05:6402:caa:b0:46b:2d74:d970 with SMTP id cn10-20020a0564020caa00b0046b2d74d970mr6445365edb.138.1673113042057; Sat, 07 Jan 2023 09:37:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Pier Paolo Grassi Date: Sat, 7 Jan 2023 18:36:46 +0100 Message-ID: Subject: Re: read with redirected stdin To: Roman Perepelitsa Cc: Zsh-Users List Content-Type: multipart/alternative; boundary="0000000000008a7d8705f1affcb2" X-Seq: 28622 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: --0000000000008a7d8705f1affcb2 Content-Type: text/plain; charset="UTF-8" oh ok, that seems what I want (except I don't want to read from stdin when there is no tty, just assume a negative answer, but that's trivial). I am still wondering, what can be a way to simulate the situation of a script launched by cron, where there is no tty and no other mean for read to connect to a terminal? thanks! Pier Paolo Grassi Il giorno sab 7 gen 2023 alle ore 18:31 Roman Perepelitsa < roman.perepelitsa@gmail.com> ha scritto: > 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 > > Roman. > --0000000000008a7d8705f1affcb2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
oh ok, that seems what I want (except I don't=C2=A0wan= t to read from stdin when there is no tty, just assume a negative answer, b= ut that's trivial).
I am still wondering,=C2=A0 what can be a way t= o simulate the situation of a script launched by cron, where there is no tt= y and no other mean for read to connect to a terminal?
thanks!

Pier Paolo Grassi


Il giorno sab 7 gen 2023 alle ore 18:31 Roman Perep= elitsa <roman.perepelitsa= @gmail.com> ha scritto:
On Sat, Jan 7, 2023 at 6:22 PM Pier Paolo Grassi <pierpaolog@gmail.com= > 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:

=C2=A0 =C2=A0 if [[ -n $TTY ]]; then
=C2=A0 =C2=A0 =C2=A0 # There is a terminal. Read from it.
=C2=A0 =C2=A0 =C2=A0 read -k1
=C2=A0 =C2=A0 else
=C2=A0 =C2=A0 =C2=A0 # There is no terminal. Read from stdin.
=C2=A0 =C2=A0 =C2=A0 read -k1 -u0
=C2=A0 =C2=A0 fi

Roman.
--0000000000008a7d8705f1affcb2--