${BASH_SOURCE[0]} equivalent in zsh?

${BASH_SOURCE[0]} equivalent in zsh is ${(%):-%N}, NOT $0(as OP said, the latter failed in .zshrc)

Here % indicates prompt expansion on the value,
%N indicates “The name of the script, sourced file,
or shell function that zsh is currently executing,

whichever was started most recently. If there is none, this is equivalent to the parameter $0.”(from man zshmisc)

Leave a Comment