LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-16-2017, 06:28 PM   #1
iAM-Mr
LQ Newbie
 
Registered: Feb 2017
Posts: 2

Rep: Reputation: Disabled
How to prevent tee from sending output to the screen?


I'm writing a script that puts a short line of text into each of the files f1, f2, and f3.
When done, the script prints a message that all files have been created. This is what I have:

touch newDir/f3 newDir/dir1/f1 newDir/dir1/f1 newDir/dir1/f2
echo This is the first line of text | tee newDir/f3 newDir/dir1/f1 newDir/dir1/f2
echo All files and subdirectories created!

The problem is that tee directs output to the files AND the screen. How do I prevent output to the screen? I tried to redirect the output by using > newDir/f3 newDir/dir1/f1 newDir/dir1/f2 (because I want to do them all in the same line), but I don't get the results I'm looking for.

Please explain your answer. Thank you in advance!
 
Old 03-16-2017, 07:22 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2.1.2 on Lenovo Thinkpad W520
Posts: 9,215

Rep: Reputation: Disabled
Code:
echo "This is the first line of text" | tee newDir/f3 newDir/dir1/f1 newDir/dir1/f2 1>/dev/null
This redirects the standard output to /dev/null which is a "fake" device.

Last edited by Didier Spaier; 03-16-2017 at 07:25 PM.
 
1 members found this post helpful.
Old 03-16-2017, 08:14 PM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,762

Rep: Reputation: 684Reputation: 684Reputation: 684Reputation: 684Reputation: 684Reputation: 684
why not jist redirect the output directly to the file? in this case tee is redundant.
 
Old 03-16-2017, 08:35 PM   #4
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 19.1 MATE
Posts: 8,018
Blog Entries: 5

Rep: Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872Reputation: 2872
echo This is the first line of text | tee newDir/f3 newDir/dir1/f1 > newDir/dir1/f2

Taken from http://stackoverflow.com/questions/1...but-not-stdout

Found through web search for linux tee not stdout

Essentially, you're using tee to redirect the input to the first two files, then redirecting stdout to the third, which has the same effect.

Just an aside that you touch newDir/dir1/f1 twice in your first line.

Last edited by hydrurga; 03-16-2017 at 08:37 PM. Reason: Explanation
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't tee $(tty) produce output on the current terminal? openSauce Linux - Newbie 12 01-18-2016 01:25 PM
How to avoid LF when redirecting output with Tee or > klaus-3140 Linux - Newbie 3 07-10-2014 08:50 AM
how do i prevent a user from sending mail onyangoliech Linux - Software 4 12-15-2006 12:24 PM
prevent user from sending mail in postfix onyangoliech Linux - Networking 1 12-14-2006 08:29 AM
Prevent Cron from sending emails carmeng Linux - Software 3 11-10-2003 06:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration