Skip to content

Print a Bash stack trace

Walk caller frames from the current function back toward main.

18th August 2026

stacktrace() {
  local start_from=${1:-0}
  local i=0

  while caller $i > /dev/null; do
    if (( "$i" + 1 >= "${start_from}" )); then
      caller $i
    fi
    ((i = i + 1))
  done
}