|
|
|
|
|
by gkfasdfasdf
337 days ago
|
|
Why not leverage the bash 'caller' builtin? It's meant for printing stack traces, e.g. #!/bin/bash
die() {
local frame=0
while caller $frame; do
((++frame));
done
echo "$*"
exit 1
}
f1() { die "*** an error occured ***"; }
f2() { f1; }
f3() { f2; }
f3
Output
12 f1 ./callertest.sh
13 f2 ./callertest.sh
14 f3 ./callertest.sh
16 main ./callertest.sh
*** an error occured ***
Via: https://bash-hackers.gabe565.com/commands/builtin/caller/ |
|