943,521 Members | Top Members by Rank

Ad:
Aug 25th, 2009
0

How not to show messages?

Expand Post »
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!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darangho is offline Offline
21 posts
since Aug 2009
Aug 25th, 2009
1

Re: How not to show messages?

Send stdout and stderr to /dev/null:
bash Syntax (Toggle Plain Text)
  1. sk@sk:~$ which bash
  2. /bin/bash
  3. sk@sk:~$ which bash >> /dev/null 2>&1
  4. sk@sk:~$

You can still access the return value which is usually why this is done. Here is an example:
bash Syntax (Toggle Plain Text)
  1. sk@sk:~$ which bash >> /dev/null 2>&1
  2. sk@sk:~$ echo $?
  3. 0
  4. sk@sk:~$ which asoija0cjas9cuasc >> /dev/null 2>&1
  5. sk@sk:~$ echo $?
  6. 1
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 25th, 2009
0

Re: How not to show messages?

Thank you very much
problem solved!

Click to Expand / Collapse  Quote originally posted by sknake ...
Send stdout and stderr to /dev/null:
bash Syntax (Toggle Plain Text)
  1. sk@sk:~$ which bash
  2. /bin/bash
  3. sk@sk:~$ which bash >> /dev/null 2>&1
  4. sk@sk:~$

You can still access the return value which is usually why this is done. Here is an example:
bash Syntax (Toggle Plain Text)
  1. sk@sk:~$ which bash >> /dev/null 2>&1
  2. sk@sk:~$ echo $?
  3. 0
  4. sk@sk:~$ which asoija0cjas9cuasc >> /dev/null 2>&1
  5. sk@sk:~$ echo $?
  6. 1
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darangho is offline Offline
21 posts
since Aug 2009
Aug 25th, 2009
0

Re: How not to show messages?

Please mark this thread as solved as you have found an answer to your question and good luck!
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: how to prevent user close window during script execution?
Next Thread in Shell Scripting Forum Timeline: Issue with sed and date variable - Suffix too large - 512 max





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC