Created
March 5, 2017 17:09
-
-
Save airtower-luna/5039f60b0e2042f29f8d792bb79fec61 to your computer and use it in GitHub Desktop.
Example script: Bash caller builtin lists wrong lineno/function in ERR trap triggered by return
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 -E | |
function commanderr | |
{ | |
false | |
} | |
function returnerr | |
{ | |
return 1 | |
} | |
function calltrace () | |
{ | |
local l=0 | |
echo -n "${l}: " | |
while caller $((l++)); do echo -n "${l}: "; done | |
echo -n -e "\r" | |
} | |
trap 'calltrace' ERR | |
commanderr | |
returnerr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment