From owner-freebsd-questions Fri Apr 13 3:14:11 2001 Delivered-To: freebsd-questions@freebsd.org Received: from ren.sasknow.com (ren.sasknow.com [207.195.92.131]) by hub.freebsd.org (Postfix) with ESMTP id 17EBC37B424 for ; Fri, 13 Apr 2001 03:14:06 -0700 (PDT) (envelope-from ryan@sasknow.com) Received: from localhost (ryan@localhost) by ren.sasknow.com (8.9.3/8.9.3) with ESMTP id EAA67804; Fri, 13 Apr 2001 04:14:02 -0600 (CST) (envelope-from ryan@sasknow.com) Date: Fri, 13 Apr 2001 04:14:02 -0600 (CST) From: Ryan Thompson To: Mark Drayton Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Finding the current terminal In-Reply-To: <20010413105407.A6788@tethys.valhalla.net> Message-ID: Organization: SaskNow Technologies [www.sasknow.com] MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 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 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