Skip to content

Instantly share code, notes, and snippets.

@ploxiln
Created January 9, 2024 06:18
Show Gist options
  • Save ploxiln/4dda904cfae5a01a8b2942d08f172e1f to your computer and use it in GitHub Desktop.
Save ploxiln/4dda904cfae5a01a8b2942d08f172e1f to your computer and use it in GitHub Desktop.
testing how bash trap affects exit code
#!/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