Source File of Functions

$BASH_SOURCE contains paths to the source files, where the functions of $FUNCNAME are defined.

Examples

Display execution position :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
a() {
  local i=$((${#FUNCNAME} - 1))
  cat << EOF
  file: ${BASH_SOURCE[i+1]}
  function: ${FUNCNAME[i]}
  executed at: ${BASH_LINENO[i]}
EOF
}

a

Output:

  file: /home/user/file.sh
  function: a
  executed at: 10
BashSupport Pro is a Bash IDE with support for $BASH_SOURCE – try it now!
© 2020–2022 Joachim Ansorg
Imprint
Privacy Policy
Legal