I have a script which compile a program. This program first compiles the source code using configure && make commands, then runs some tests using make test. This script also uses set -e to catch errors.

Now, what I want to do is keep set -e set in the script and still continue running the script when make test encounters some errors. I have tried using make -k test to make the tests run even when it encounters errors, but it is caught by the set -e command and it is stopped.

I also know which tests are going to fail, so is there any way to tell the script to skip catching these errors.

I need help regarding these two questions urgently as I have very little knowledge in shell scripting.

share|improve this question
up vote 5 down vote accepted
make test || true

e.g.

#!/bin/sh
set -e
echo hello
make test || true
echo done

Will result in

hello
make: *** No rule to make target `test'.  Stop.
done

In this case the failure was a missing rule (no Makefile :-)) but we can see the script continues.

share|improve this answer

set -e can be flipped with set +e.

#!/bin/sh
set -e
configure && make
set +e
make test
...
share|improve this answer
    
Isn't there any other way to do it? As in more robust way? – Abhimanyu Saharan Jun 22 '16 at 18:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.