Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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:
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.