Sample Header Ad - 728x90

How can I suppress output only if the command succeeds?

31 votes
6 answers
18603 views
I would like to simplify the output of a script by suppressing the output of secondary commands that are usually successful. However, using -q on them hides the output when they occasionally fail, so I have no way of understanding the error. Additionally, these commands log their output on stderr. Is there a way to suppress a command's output **only if it succeeds**? For example (but not limited to) something like this: mycommand | fingerscrossed If all goes well, fingerscrossed catches the output and discards it. Else it echoes it to the standard or error output (whatever).
Asked by Matthieu Napoli (1202 rep)
Jan 18, 2016, 05:04 PM
Last activity: Sep 7, 2024, 05:33 AM