Search code examples
linuxbashdotfiles

How to know which file sourced a particular file


Ubuntu 16.04; zsh; oh my zsh; KDE

I have many dotfiles like .bashrc, .commonrc, .zshrc sourcing each other. Say I want to stop sourcing a particular file .bash_docker. Is there a way to know which file sourced it?

I figured it out through manual examination, but it happens quite often... It seems like source has no man page or help option.


Solution

  • Try printing this in your target script

    echo "This script sourced from : ${BASH_SOURCE[1]}"
    

    Here are the bash variables of interest for reference https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html