Hi all
I just have questions about
how not to show messages after you execute a certain command.

for example whenever you execute "which xxx"
there will always be a message on the terminal
saying its path or command not found will be written.

is that possible to write a shell script file
without showing these kind of messages?

Thanks!

Send stdout and stderr to /dev/null:

sk@sk:~$ which bash
/bin/bash
sk@sk:~$ which bash >> /dev/null 2>&1
sk@sk:~$

You can still access the return value which is usually why this is done. Here is an example:

sk@sk:~$ which bash >> /dev/null 2>&1
sk@sk:~$ echo $?
0
sk@sk:~$ which asoija0cjas9cuasc >> /dev/null 2>&1
sk@sk:~$ echo $?
1

Thank you very much
problem solved!

Send stdout and stderr to /dev/null:

sk@sk:~$ which bash
/bin/bash
sk@sk:~$ which bash >> /dev/null 2>&1
sk@sk:~$

You can still access the return value which is usually why this is done. Here is an example:

sk@sk:~$ which bash >> /dev/null 2>&1
sk@sk:~$ echo $?
0
sk@sk:~$ which asoija0cjas9cuasc >> /dev/null 2>&1
sk@sk:~$ echo $?
1

Please mark this thread as solved as you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.