View Single Post
Posts: 67 | Thanked: 36 times | Joined on May 2010 @ Claremont (LA), California
#291
Originally Posted by petrelli View Post
My question, how could I hide the output text? I am only interested in the exit code, not in the text.

I imagine I can use awk, but I think it is not too elegant. Is there something I am missing here??

Thx
There are a couple of approaches. You can dump any output by redirecting it to /dev/null:

Code:
mycommand > /dev/null
(if "mycommand" is sufficiently complex, parenthesize it). But I think that if your script produces no output whatsoever, QBW replaces its results with "No Output". So what you really want to do is to do the echo, but not affect the status. That takes a slight bit of shell magic:

Code:
mycommand > /dev/null; s=$?; echo " "; exit $s
Here, $? is the exit status of the previous command (mycommand). You save it in the variable s, do the echo, and then explicitly make s be the exit status.

Warning: don't put blanks around the equals sign. The shell doesn't like that.