Created
November 27, 2019 20:29
-
-
Save Oppodelldog/133e349df97bd645f2ad4a80ed219e9f to your computer and use it in GitHub Desktop.
shell - nested traps
This file contains 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 | |
err_report() { | |
echo "error in inner script: $(caller):$1" | |
} | |
trap 'err_report $LINENO' ERR | |
echo "INNER SCRIPT" | |
false |
This file contains 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 | |
err_report() { | |
echo "error in outer script: $(caller):$1" | |
} | |
trap 'err_report $LINENO' ERR | |
echo "OUTER SCRIPT" | |
./inner.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to know what happens if I have nested shell scripts both adding a error trap.
the output of calling ./outer.sh :
This is what I wished it would be, so I can add some cleanup in the nested script, but the outer scripts also will do its cleanup.