Is there a way for a sourced shell script to find out the path to itself? I'm mainly concerned with bash, though I have some coworkers who use tcsh.I'm guessing I may not have a ton of luck here, since sourcing causes commands to be executed in the current shell, so $0 is still the current shell's invocation, not the sourced script. My best thought currently is to do source $script $script, so that the first positional parameter contains the necessary information. Anyone have a better way?To be clear, I am sourcing the script, not running it:source foo.bash
determining path to sourced shell script
shell;source
In tcsh, $_ at the beginning of the script will contain the location if the file was sourced and $0 contains it if it was run.#!/bin/tcshset sourced=($_)if ($sourced != ) then    echo sourced $sourced[2]endifif ($0 != tcsh) then    echo run $0endifIn Bash:#!/bin/bashcalled=$_[[ $called != $0 ]] && echo Script is being sourced || echo Script is being runecho \$BASH_SOURCE ${BASH_SOURCE[@]}