Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Testing if a file is a terminal?
- X-seq: zsh-users 13559
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "Zsh users list" <zsh-users@xxxxxxxxxx>
- Subject: Re: Testing if a file is a terminal?
- Date: Tue, 09 Dec 2008 09:31:39 -0800
- In-reply-to: <6cd6de210812090847i1d0d76b8wf107e5c8ea2f0f9e@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <6cd6de210812090847i1d0d76b8wf107e5c8ea2f0f9e@xxxxxxxxxxxxxx>
On Dec 9, 11:47am, Rocky Bernstein wrote:
}
} 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.
Hence you think [[ -t 0 ]] < "$1" is going to cause a problem because
it opens and closes the device.
If that's so, you do this:
exec {ttyfd}<>"$1"
[[ -t $ttyfd ]]
Now $ttyfd remains open for read and write, and future redirections
can use it, e.g.
print -u $ttyfd "This is $1"
cat < /etc/termcap >&$ttyfd
I'm not sure of the context, so somehow you have to get $ttyfd to be
visible both where you're testing the tty-ness of $1 and wherever it
is you wanted to use $1 for I/O.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author