Solved

using back quotes with tty

Posted on 2007-03-19
3
506 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell Script on AIX 7 64
nagios 4 php error after installation 6 78
How to install Ubuntu 16 in DELL venue 8 pro 20 51
Debugging a shell script 3 14
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now