LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-12-2010, 04:23 AM   #1
mohit_parihar
LQ Newbie
 
Registered: Nov 2009
Posts: 28

Rep: Reputation: 15
echo command


as we know that echo displays msg. By typing command echo hi > /dev/null , the output hi is directed in the null. sir my question is can i define any variable in place of hi such that any one who uses echo command gets nothing as output as all its output is directed in null. such as the syntax becomes like
echo "*" > /dev/null
where "*" is a generalized variable. such that any thing written in that place is redirected to null. if this is possible then how? I know i have to do some coding for the variable. but how to start it.
 
Old 01-12-2010, 04:57 AM   #2
bradvan
Member
 
Registered: Mar 2009
Posts: 367

Rep: Reputation: 61
I'm confused.

First, it is not echo that is sending the output to null. It is the shell. It doesn't matter if you echo something and redirect the standard output to null or if you run some other command and redirect its standard output to null. The shell will do that. If you don't want the output of echo $VAR being seen by anyone, just don't echo the variable.

If you are trying to say you want to change the echo command so that it dumps all output to /dev/null, then that is a different story. Some shells have echo built into them. You would have to get the source and change the built in echo. You would also have to get the source to the /bin/echo and change it. Not much use for echo then. I must be misunderstanding what you want.

What are you trying to accomplish?
 
Old 01-12-2010, 05:42 AM   #3
mishkind
LQ Newbie
 
Registered: Nov 2007
Posts: 10

Rep: Reputation: 0
If you want to completely disable the echo command, you can try replacing the echo with your own modified script.
E.G.:
1. Move /bin/echo to /bin/echo.private (or something similar)
2. create a /bin/echo script that will take the parameters passed to it and send it to /dev/null.
Something like:
in the new /bin/echo:

/bin/echo.private $@ > /dev/null

Hope that helps.
 
Old 01-12-2010, 06:54 AM   #4
vrmartin2
Member
 
Registered: Dec 2009
Location: NE Ohio
Distribution: Open SUSE
Posts: 43

Rep: Reputation: 19
Redirecting Output

Or you could do this:

exec 1>/dev/null
exec 2>&1

This results in both standard out and standard err being routed to /dev/null from that point on in the script.

Here are other examples of this type of redirection:

exec 3> file3.txt # now file descriptor 3 is writing to file3.txt
exec 4< file3.txt # now file descriptor 4 is reading from file3.txt

Some of this is courtesy of an ancient book I have called "The Unix Shell Programming Language" by Manis and Meyer. It's an old favorite of mine, and this syntax is still current.

Last edited by vrmartin2; 01-12-2010 at 06:55 AM. Reason: syntax correction
 
  


Reply

Tags
bash, echo, exec, redirection, sh, stderr, stdout



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command echo Corrado Linux - Newbie 3 11-11-2009 06:44 PM
echo: command or built-in? colucix Linux - General 5 01-06-2008 11:55 AM
echo command s_hcl Linux - General 1 09-06-2006 05:27 AM
what is the echo command in perl? hamish Programming 5 12-14-2004 08:31 AM
echo command peculiarity eallen Linux - General 3 02-11-2003 05:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:01 PM.

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
Open Source Consulting | Domain Registration