3

I'm looking for a way to continue a make command in the event of a error failure.

I need a way of wrapping a command so it doesn't respond with a exit code 1.

test:
    exit 1 ;\
    echo 'hi' ;\

I need a way to wrap something like this:

example:
   somecommand && othercommand ;\
   echo 'hi' ;\

Where somecommand can exit with a 1 (error) and not run othercommand or a 0 which would run othercommand.

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • how about `badcommand || true` ? – carsten Jun 11 '16 at 23:39
  • Just tried it, still not running `echo 'hi'` – ThomasReggi Jun 11 '16 at 23:40
  • 1
    The problem is that `exit` is a little more intrusive than just a failing command, because `exit` actually quits the shell. If your Makefile literally contains `exit`, you have to wrap it like this: `$(shell exit 1 || true)`. For any other command that simply fails, the extra wrapping is not required. – carsten Jun 11 '16 at 23:43

3 Answers3

2

This should do:

test:
    commandThatMayFail && otherCommand || true
    echo hi

You can try it like this:

test:
    rm fileDoesNotExist && echo foo || true
    echo bar
carsten
  • 1,315
  • 2
  • 13
  • 27
2

You can also use make -i ... to ignore all errors. Per the man page:

-i, --ignore-errors

Ignore all errors in commands executed to remake files.

Andrew Henle
  • 32,625
  • 3
  • 24
  • 56
2

Prefixing a recipe with - tells make to ignore any errors returned by that line, the only other thing you need to do is run the two recipes separately.

example:
   -somecommand && othercommand
   echo 'hi'
user657267
  • 20,568
  • 5
  • 58
  • 77