1 | #!/usr/bin/env bash |
2 | # |
3 | # Usage: |
4 | # demo/bash-call-stack.sh |
5 | |
6 | f() { |
7 | echo 'hi from f' |
8 | g |
9 | } |
10 | |
11 | g() { |
12 | echo 'hi from g' |
13 | |
14 | local n=${#BASH_SOURCE[@]} |
15 | for (( i = 0; i < n; ++i)); do |
16 | echo "STACK:${BASH_SOURCE[i]}:${FUNCNAME[i]}:${BASH_LINENO[i]}" |
17 | done |
18 | } |
19 | |
20 | # -1 position is the bottom of the stack |
21 | # |
22 | # It has has demo/bash-stack.sh:main:0 |
23 | # |
24 | # This is tested in spec/introspect.sh |
25 | |
26 | #PS4='+ ${BASH_SOURCE[-1]}:${FUNCNAME[-1]}:${BASH_LINENO[-1]} ' |
27 | #set -x |
28 | f |