3 ms·
What a nonsense. Instead of handling non-zero exit statuses in a correct way,the article suggests to interrupt the script right in the middle, with probably so
by plugnburn 11y ago
What a nonsense.
Instead of handling non-zero exit statuses in a correct way,the article suggests to interrupt the script right in the middle, with probably some temporary files and processes hanging around which can't be cleaned up if something goes wrong.
The same BS goes though the entire article.
Has the author actually written anything bigger than echo "Hello world!" in Bash?
- zurn 11y agoIn bash you clean up in the exit handler: trap mycleanupfunc EXIT
- plugnburn 11y agoI'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.
- rcxdude 11y agoClearly silently ignoring errors is the better approach. Or, if you are actually handling errors, then it doesn't matter either way.