FUNCNAME

 cat main
#!/bin/bash
. lib1.sh
. lib2.sh
func1


ubuntu2@ubuntu2:~/temp$ cat lib1.sh 
#!/bin/bash
function func1()
{
echo "func1: FUNCNAME0 is ${FUNCNAME[0]}"
echo "func1: FUNCNAME1 is ${FUNCNAME[1]}"
echo "func1: FUNCNAME2 is ${FUNCNAME[2]}"
echo "func1: BASH_SOURCE0 is ${BASH_SOURCE[0]}"
echo "func1: BASH_SOURCE1 is ${BASH_SOURCE[1]}"
echo "func1: BASH_SOURCE2 is ${BASH_SOURCE[2]}"
echo "func1: LINENO is ${LINENO}"
func2
}

ubuntu2@ubuntu2:~/temp$ cat lib2.sh 
function func2()
{
echo "func2: FUNCNAME0 is ${FUNCNAME[0]}"
echo "func2: FUNCNAME1 is ${FUNCNAME[1]}"
echo "func2: FUNCNAME2 is ${FUNCNAME[2]}"
echo "func2: BASH_SOURCE0 is ${BASH_SOURCE[0]}"
echo "func2: BASH_SOURCE1 is ${BASH_SOURCE[1]}"
echo "func2: BASH_SOURCE2 is ${BASH_SOURCE[2]}"
# This comment makes lib2.sh different from lib1.sh
echo "func2: LINENO is ${LINENO}"
}


bash main
func1: FUNCNAME0 is func1
func1: FUNCNAME1 is main
func1: FUNCNAME2 is 
func1: BASH_SOURCE0 is lib1.sh
func1: BASH_SOURCE1 is main
func1: BASH_SOURCE2 is 
func1: LINENO is 10
func2: FUNCNAME0 is func2
func2: FUNCNAME1 is func1
func2: FUNCNAME2 is main
func2: BASH_SOURCE0 is lib2.sh
func2: BASH_SOURCE1 is lib1.sh
func2: BASH_SOURCE2 is main
func2: LINENO is 10
ubuntu2@ubuntu2:~/temp$ 

Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all