Date: Fri, 13 Apr 2001 04:14:02 -0600 (CST) From: Ryan Thompson <ryan@sasknow.com> To: Mark Drayton <mark.drayton@4thwave.co.uk> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Finding the current terminal Message-ID: <Pine.BSF.4.21.0104130357250.51013-100000@ren.sasknow.com> In-Reply-To: <20010413105407.A6788@tethys.valhalla.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Mark Drayton wrote to freebsd-questions@FreeBSD.ORG: > Thierry Black (thierryblack@hotmail.com) wrote: > > Can anyone tell me how to find (and output) the name of the current > > terminal? Something relatively cross-platform and non-shell-specific > > would be ideal. > > [mark@nyx mark]$ tty > /dev/ttyp0 > > Any good? And, if you're curious, the following one line C program will also do the trick, assuming it IS run from a terminal (/usr/bin/tty is just a more complex version of this). #include <stdio.h> void main() { (void)printf("%s\n", ttyname(0)); } ryan@ren:/home/ryan $> cc -o mytty mytty.c ryan@ren:/home/ryan $> mytty /dev/ttyv2 ( Recommendation: Just use tty(1)... it's pretty much been around since day 1.. So I think it qualifies for "cross platform" and "non-shell-specific" :-) On some systems, I like to include the terminal in my shell prompts for interactive logins. In Bourne shells, export PS1="`tty | cut -c 6-` $USER@....whatever else you like to put in your prompt" - Ryan -- Ryan Thompson <ryan@sasknow.com> Network Administrator, Accounts SaskNow Technologies - http://www.sasknow.com #106-380 3120 8th St E - Saskatoon, SK - S7H 0W2 Tel: 306-664-3600 Fax: 306-664-1161 Saskatoon Toll-Free: 877-727-5669 (877-SASKNOW) North America To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0104130357250.51013-100000>