0

I have a few different bash scripts and want a way to check if any command included in the script had an error. Something like this in python to then check if there was an error or not.

The only thing close to this that I know in bash is $? but afaik that can only be used to check if the last executed command had an error.

For an example here is one of the scripts.

Icoryx
  • 96
  • 7
  • @Poshi not quiet as it only checks for the exitcode of the last executed command. I'm looking for something similar like this that returns an exitcode for the whole script without having to check every single command manually. – Icoryx Mar 08 '22 at 09:57
  • 1
    It's not really clear what you want. `set -e` will force the script to exit on any error. `trap '...' ERR` will cause Bash to run the commands in the trap when there is an error. Both of these are questions which have been answered before. – tripleee Mar 08 '22 at 11:08
  • AFAIK, there's nothing like you are looking for. You either check each command or fail at the first error. All languages I know work this way: fail at the first error or each command returning an error code. – Poshi Mar 08 '22 at 11:21

0 Answers0