3 ms·
I've read it, don't worry. So basically we create a problem with the use of -e flag and then solve it with traps... And what if our logic depends on exit status
by plugnburn 11y ago
I've read it, don't worry. So basically we create a problem with the use of -e flag and then solve it with traps... And what if our logic depends on exit statuses, for example when we check whether some utility or a file is present in the system? I don't want the script to exit, I want it to go another logic branch!
P.S. No, temporarily disabling the option is not a solution, it's another workaround for the problem created out of nothing.
- matt_kantor 11y agoExit traps for cleanup are a good idea in any case. Scripts can be killed by signals and whatnot as well. I'm not sure what scenario you're imagining with your other concern. This does what you would expect: set -o errexit if [ -f somefile ] then echo "File exists." else echo "File does not exist." fi
- deleted 11y ago[deleted]
- rcxdude 11y agoDo you understand how the flag works? You can still condition on exit status. It's only if you have an 'unhandled' exit status that causes script termination.