This is an old revision of the document!

The caller builtin command


The caller builtin command is used to print execution frames of subroutine calls. Without giving a framenumber, the topmost execution frame information is printed ("who called me") wile linenumber and filename.

When an execution frame number is given (0 - topmost), the linenumber, the subroutine (function) and the filename is printed. When an invalid execution frame number is given, it exists FALSE. This way it can be used in a loop (see the examples section below).

The code below defines a function die that is used to exit the program. It prints a list of execution frames, starting with the topmost frame (0). The topmost frame is the "caller of the die function", in this case function "f1".

This way, you can print a kind of "stack trace" for debugging or logging purposes.

The code is made very simple, just to show the basic purposes.

die() {
  local frame=0
  while caller $frame; do
  echo "$*"
  exit 1
f1() {
  die "*** an error occured ***"
f2() {
f3() {


15 f1 ./
19 f2 ./
23 f3 ./
26 main ./
*** an error occured ***

  • caller is not specified by POSIX(R)
  • the caller builtin command appeared in Bash version 3.0
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
You could leave a comment if you were logged in.
  • commands/builtin/caller.1285134714.txt
  • Last modified: 2012/01/15 09:09
  • (external edit)