Tuesday, January 18, 2011

What BASH_SOURCE does..

http://stackoverflow.com/questions/1178751/how-can-you-access-the-base-filename-of-a-file-you-are-sourcing-in-bash

What does BASH_SOURCE do? The documentation at http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html is really vague, so you really need to try it.

vi a.sh:
echo ${BASH_SOURCE[0]}
source b.sh

vi b.sh:
echo ${BASH_SOURCE[0]} ${BASH_SOURCE[1]}

/tmp$ source a.sh
rhu@rhu-linux:/tmp$ source a.sh
a.sh
b.sh a.sh

1 comment: