Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Testing if a file is a terminal?
- X-seq: zsh-users 13558
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Rocky Bernstein <rocky.bernstein@xxxxxxxxx>
- Subject: Re: Testing if a file is a terminal?
- Date: Tue, 9 Dec 2008 17:06:38 +0000
- Cc: Zsh users list <zsh-users@xxxxxxxxxx>
- In-reply-to: <6cd6de210812090847i1d0d76b8wf107e5c8ea2f0f9e@xxxxxxxxxxxxxx>
- Mail-followup-to: Rocky Bernstein <rocky.bernstein@xxxxxxxxx>, Zsh users list <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <6cd6de210812090847i1d0d76b8wf107e5c8ea2f0f9e@xxxxxxxxxxxxxx>
On Tue, Dec 09, 2008 at 11:47:51AM -0500, Rocky Bernstein wrote:
> First, many thanks to Peter and Stéphane for the very informative
> answers on terminal redirection.
>
> Before allowing a terminal to be set, the zshdb debugger uses this test:
>
> [[ -r "$1" && -w "$1" ]] && return 0 # Ok
>
> $1 is a string -- the device name (e.g. /dev/pts/1) -- not a file descriptor.
>
> But is this really the best one can do? I suppose on could also add a
> test if the device is a character device but I just wonder if there
> isn't a better way.
>
> isatty() works on a file descriptor, but we don't have that yet. I
> suppose one could try to open that and then test but then care needs
> to be made to use that opened file descriptor and not say close and
> reopen that.
>
> Any other thoughts or suggestions?
[...]
You could compare the device major and type to that of $TTY
(using zstat). [ -t <fd> ] tests whether a fd is a terminal (in
any shell, not only zsh).
But why would you want to check for that?
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author