zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Zsh-Users List <zsh-users@zsh.org>
Cc: Pier Paolo Grassi <pierpaolog@gmail.com>
Subject: Re: read with redirected stdin
Date: Sun, 8 Jan 2023 14:21:57 +0000	[thread overview]
Message-ID: <20230108142157.GM8411@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <CAN=4vMoQTe=3-EhiR-W=LrotHpZcx3yYN9eKOtL3aKcsYZU5Vw@mail.gmail.com>

Roman Perepelitsa wrote on Sun, Jan 08, 2023 at 14:48:24 +0100:
> On Sun, Jan 8, 2023 at 2:30 PM Daniel Shahaf <d.s@daniel.shahaf.name> 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 <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:
> > >
> > >     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.
> 


  reply	other threads:[~2023-01-08 14:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-07 13:31 Pier Paolo Grassi
2023-01-07 13:44 ` Roman Perepelitsa
2023-01-07 17:21   ` Pier Paolo Grassi
2023-01-07 17:31     ` Roman Perepelitsa
2023-01-07 17:36       ` Pier Paolo Grassi
2023-01-07 17:52         ` Roman Perepelitsa
2023-01-08 13:23       ` Daniel Shahaf
2023-01-08 13:48         ` Roman Perepelitsa
2023-01-08 14:21           ` Daniel Shahaf [this message]
2023-01-08 14:42             ` Roman Perepelitsa
2023-01-07 17:33     ` Pier Paolo Grassi
2023-01-08  4:28     ` Jim
2023-01-08  4:44       ` Pier Paolo Grassi
2023-01-08 21:18         ` Jim
2023-01-09 16:01           ` Pier Paolo Grassi
2023-01-09 22:47             ` Jim
2023-01-10  2:46               ` Bart Schaefer
2023-01-10  6:03                 ` Pier Paolo Grassi
2023-01-08 14:44       ` Ray Andrews
2023-01-08 15:06         ` Roman Perepelitsa
2023-01-08 20:23           ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230108142157.GM8411@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=pierpaolog@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).