On 2008-07-09 at 10:05 -0700, William Scott wrote:
If, while in zsh, I type
source /whole/path/to/sourcefile
and have dirname $0 embedded within the sourcefile
In zsh, it will report back the full directory path for the directory
in which this file is located, the same way it does for shell
scripts.
In bash, I just get the location of the bash executable itself.
Is there an equivalent command that will work in bash (or preferably
both shells)?
Both shells:
dirname ${BASH_SOURCE:-$0}
In bash, BASH_SOURCE is an array variable but referring to an array
gets
you the first element only (unless you explicitly expand the array),
so
you have the value. In zsh, unless you've got something exporting
BASH_SOURCE to the environment,the variable will be unset, so you get
the default value, $0 which should give you the same thing.
Phil