outsource from india chennai india programmers freelance php coder freelance outsource scripts programming complicated perl patterns php module installation
outsource from india perl installation and configuration php installation linux system administration US$15,US$19,US$11,US$10 cheap programmer
india outsource outsource india chennai india programmers php perl mysql freelance freelance programmer
SHOWCASE of php and perl scripts CONTACT US for php custom perl scripts
HOME
 

11.5. Checking the Current TTY

The tty command returns the filename of the terminal connected to standard input. This comes in two formats on the Linux systems I have used, either "/dev/tty4" or "/dev/pts/2". I've used several methods over time, but the simplest I've found so far (probably both Linux- and Bash-2.x specific) is temp=$(tty) ; echo ${temp:5}. This removes the first five characters of the tty output, in this case "/dev/".

Previously, I used tty | sed -e "s:/dev/::", which removes the leading "/dev/". Older systems (in my experience, RedHat through 5.2) returned only filenames in the "/dev/tty4" format, so I used tty | sed -e "s/.*tty\(.*\)/\1/".

An alternative method: ps ax | grep $$ | awk '{ print $2 }'.

Relative speed: the ${temp:5} method takes about 0.12 seconds on an unloaded 486SX25, the sed-driven method takes about 0.19 seconds, the awk-driven method takes about 0.79 seconds.


Linux HOWTO full list
   This document, LDP HOWTO-INDEX, is copyrighted (c) 1995 - 2002 by Tim Bynum, Guylhem Aznar, Joshua Drake and Greg Ferguson. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is available at http://www.gnu.org/copyleft/fdl.html. If you have questions, please contact the LDP.
Web Design Copyright © 1999-2003. Chrisranjana Software Solutions Pvt Ltd. syndicate rss feed