Solved

using back quotes with tty

Posted on 2007-03-19
3
508 Views
Last Modified: 2012-06-27
I am trying to understand why the following statement works the same as the cat command.

cp filename `tty`   - this will output the contents of filename on the screen.
cat filename - this does the exact same thing as the above.  

Can someone explain to me why the cp command works?  Im new to linux and this is not making sense.
0
Comment
Question by:monica73174
3 Comments
 
LVL 9

Accepted Solution

by:
paradoxengine earned 500 total points
ID: 18751045
cp will copy the contents of a file to another one.
In unix EVERYTHING is a file.
This said, the backticks are doing "command substitution".

try tty | xargs cp filename : it's the same thing.
What you are doing by  cp filename `tty` is doing a CP from filename to /dev/pts/1 (for instance: run tty from your shell. the backticks will put the return value of the program instead of the program name). tty is the terminal "file": that's it, you are piping data from a file to another file (the terminal).
Hope it was clear enough :-)
0
 

Author Comment

by:monica73174
ID: 18751358
That is a fantastic explaination.  It took me a few seconds to absorb what it was you were saying but now it makes perfect sense.  Thank you so much!  
0
 
LVL 48

Expert Comment

by:Tintin
ID: 18751936
Another way of thinking about this is doing

cat filename >`tty`

That will produce the same output as

cat filename

ie: display it on your terminal.

If you have permissions to do so (generally requires root access), you can write to other peoples displays, eg:

cat filename >/dev/ptys/2

Where /dev/ptys/2 is the terminal that someone else is logged into.

That's effectively what the 'wall' command does.  It broadcasts to all logged on users by displaying the message directly to their tty device.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to moveā€¦
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

808 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