LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   echo command (https://www.linuxquestions.org/questions/linux-general-1/echo-command-781659/)

mohit_parihar 01-12-2010 04:23 AM

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.

bradvan 01-12-2010 04:57 AM

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?

mishkind 01-12-2010 05:42 AM

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.

vrmartin2 01-12-2010 06:54 AM

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.


All times are GMT -5. The time now is 02:53 AM.