Zsh Mailing List Archive
Messages sorted by:
Re: Testing if a file is a terminal?
- X-seq: zsh-users 13561
- From: "Rocky Bernstein" <rocky.bernstein@xxxxxxxxx>
- To: "Zsh users list" <zsh-users@xxxxxxxxxx>
- Subject: Re: Testing if a file is a terminal?
- Date: Tue, 9 Dec 2008 13:35:43 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=3I+j2pJMpdb9xI31phwrO4xL4ytZBhPdL4YVATq3ano=; b=ThmhpK6+W7chaGgmqzwx/vUNzrbfHg021Afsvju0TEENu83vaOFSZRo6oMXgzCpnPI Lyb+Kis5mWI17S7EbkJtVpCHkwDixhhWkHxT+j5XDFJ9mrZx5uS5gJrHDPjLWbhXYilY MF6VLIas4CLj8WSGjE/lyZe+rhKR+BBAx6jUo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=Gb3/jNRIedHuli4Zpxiyuj4GmtcYCTFZ0BT7ggPRbr/OKEAX5qW83JyNu6idpOWegs nkpnudCZobmebGFvF46TB0+yPVRt1E3nmbu5JUjrM/O0y5h5GY8Tdk/SWaB51SMYSDUy xDEhF80wN/OWCQqfVpkr+pKQXCBTqizrlIeoA=
- In-reply-to: <20081209170638.GE5462@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <6cd6de210812090847i1d0d76b8wf107e5c8ea2f0f9e@xxxxxxxxxxxxxx> <20081209170638.GE5462@xxxxxxxxxxxxxxx>
On Tue, Dec 9, 2008 at 12:06 PM, Stephane Chazelas
> 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).
Ok - that seems like a reasonable thing to do.
> [ -t <fd> ] tests whether a fd is a terminal (in
> any shell, not only zsh).
> But why would you want to check for that?
Just because it is a reliable way to test for terminal-ness. So if I
can open a tty, see if that works, and if so get the associated file
descriptor for that then it would be a way to see if the device name
is a terminal.
But of course this is a bit involved and I'd only contemplate that if
there were nothing better.
Messages sorted by: