With the help of @lzh on #perl I got this peace :
$ perl -we '$tty=qx(tty);$tty=~s/.*d...(.*)/$1/;print $tty'
to yield the pts/# out of tty's output(/dev/pts/#). I was
just wondering if anyone would come up with something
different or even faster. I have question though, why is
$1 better than \1? \1 works, but Perl suggest using
$1.
Originally posted as a Categorized Question.