-
Notifications
You must be signed in to change notification settings - Fork 9
/
bash-stack
42 lines (36 loc) · 858 Bytes
/
bash-stack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
PRINT_STACK () {
local i=0, STR=''
for ((i=${#FUNCNAME[@]}-2; i>=0; i--)); do
STR="$STR>${FUNCNAME[i+1]}"
done
echo $STR
}
# from http://blog.yjl.im/2012/01/printing-out-call-stack-in-bash.html
LSLOGSTACK () {
local i=0
local FRAMES=${#BASH_LINENO[@]}
# FRAMES-2 skips main, the last one in arrays
for ((i=FRAMES-2; i>=0; i--)); do
echo ' File' \"${BASH_SOURCE[i+1]}\", line ${BASH_LINENO[i]}, in ${FUNCNAME[i+1]}
# Grab the source code of the line
sed -n "${BASH_LINENO[i]}{s/^/ /;p}" "${BASH_SOURCE[i+1]}"
done
}
##
LSLOGSTACK () {
local i=0
local FRAMES=${#BASH_LINENO[@]}
# FRAMES-2 skips main, the last one in arrays
for ((i=FRAMES-2; i>=0; i--)); do
echo -n "> ${FUNCNAME[i+1]} "
done
echo
}
function hebelek2() {
LSLOGSTACK
}
function hebelek() {
hebelek2 $@
LSLOGSTACK
}
hebelek a b c