Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: read with redirected stdin
- X-seq: zsh-users 28628
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Cc: Pier Paolo Grassi <pierpaolog@xxxxxxxxx>
- Subject: Re: read with redirected stdin
- Date: Sun, 8 Jan 2023 14:21:57 +0000
- Archived-at: <https://zsh.org/users/28628>
- Feedback-id: i425e4195:Fastmail
- In-reply-to: <CAN=4vMoQTe=3-EhiR-W=LrotHpZcx3yYN9eKOtL3aKcsYZU5Vw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAP+y1xBo2fS--G8k+PbwEwJJx2d_s7ZxAJWrTNTJpE+MBB2x2w@mail.gmail.com> <CAN=4vMo5EJTiExmGxt2cxD2=_5PC0b=NCSEdZQRda+kvshg2=Q@mail.gmail.com> <CAP+y1xBGBDhmf3uQmxoTrkakTc_1=n54OtH3MC6eTdtsACJFiA@mail.gmail.com> <CAN=4vMqDbbQnimVEbhboTXNOvwrEC97Cjijc3_Q+_q0kUDfN6A@mail.gmail.com> <20230108132350.GL8411@tarpaulin.shahaf.local2> <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@xxxxxxxxxxxxxxxxxx> 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@xxxxxxxxx> 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.
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author