Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent bash from printing “<PID> Aborted” messages

Tags:

bash

shell

I've got a test script that runs a small app over and over again with various inputs:

# test_script.sh

for input1 in $some_range; do
    for input2 in $some_other_range; do
        if ! ./my_app $input1 $input2 2>/dev/null; then
            echo "ERROR: app failed with inputs: $input1 $input2"
        fi
    done
done

This is all well and good, except when it fails I get two messages, the 'ERROR' message I want, and then another (apparently from bash?) alerting me that my app was aborted:

test_script.sh: line 10:   641 Aborted           ./my_app $input1 $input2
ERROR: app failed with inputs: XXX YYY

How do I prevent the 'Aborted' messages?

Also note: The app is probably failing on a standard C library 'assert' statement.

like image 675
aaronstacy Avatar asked Feb 06 '11 06:02

aaronstacy


2 Answers

I just ran into this too. It seems that bash itself prints this unilaterally if a child process returns with status code 134, indicating the child recieved SIGABRT. The solution is to run the child process in a subshell, then ensure the subshell returns a different (still non-zero) status code on failure and has its output redirected to /dev/null. For example:

if ! ( ./myapp || false ) >/dev/null 2>&1; then
    ...
fi
like image 176
llasram Avatar answered Nov 02 '22 11:11

llasram


Try disabling job control:

set +m
like image 22
marco Avatar answered Nov 02 '22 11:11

marco