$BASH_SOURCE  –  Source File of Functions

$BASH_SOURCE is an array and contains paths to the source files of the functions contained in $FUNCNAME. ${BASH_SOURCE[i]} contains the source file, where the function ${FUNCNAME[i]} is 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
BashSupport Pro is a Bash IDE with support for $BASH_SOURCEtry it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal