Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Getting tty name from script

Posted on 1998-10-12
3
337 Views
Last Modified: 2012-06-27
How can I determine what is the current tty name? The only way I know is to issue "system("tty") > somefile" and read the file afterwards.
0
Comment
Question by:dda
3 Comments
 
LVL 2

Accepted Solution

by:
alexbik earned 50 total points
ID: 1205272
Hi,

You don't need to redirect the output from the tty command to a file, this also works:

#!/usr/bin/perl
my($tty)=`/usr/bin/tty`;
chop ($tty);
print "Current tty is: $tty\n";

Don't forget the chop, or you'll have a newline after the tty name.
0
 
LVL 4

Author Comment

by:dda
ID: 1205273
This is much easier than I thought!
0
 
LVL 84

Expert Comment

by:ozo
ID: 1205274
#also:
use POSIX;
$tty=POSIX::ttyname(2);
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
rename outfile before writing 2 74
Replace  text in a file 2 114
Ned Perl Snippet to Read Files in Directory 5 74
Regex rule to match two different url 5 74
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question