Created
January 9, 2024 06:18
-
-
Save ploxiln/4dda904cfae5a01a8b2942d08f172e1f to your computer and use it in GitHub Desktop.
testing how bash trap affects exit code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e -u | |
WORK_STATUS=${1:-0} | |
TRAP_STATUS=${2:-0} | |
work() { | |
echo working | |
return $WORK_STATUS | |
} | |
cleanup() { | |
echo cleanup | |
return $TRAP_STATUS | |
} | |
echo starting | |
trap "cleanup" EXIT | |
work | |
echo done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment