which "$(echo $0)"
should work no matter the invokation ;p
if full path, it still returns full path, if just "bash" or such it finds it from $PATH, badoom!
The only reason anyone would want to say "$($echo $0)", echoing the variable through a subshell and substituting it with itself, is to rely on the subshell parameter splitting to remove duplicate field separators from the variable.
That is likely not the case there, and any such file names are unlikely to exist. Just say: which "$0"
As the author notes in the 2nd section, that will return the location of the shell binary in the user path, which is not necessarily the one that is currently running.
Yeah, it's a little meta. I was afraid that what I was trying to say wouldn't quite come across. It's why I mentioned "the shell I'm currently typing in" so many times.
echo $0 will tell you the exact path if it was so executed as a login shell (or otherwise with a full path). If the shell was executed otherwise, then 'which $0' will tell you where it came from, because it must have come from $PATH.
> If the shell was executed otherwise, then 'which $0' will tell you where it came from, because it must have come from $PATH.
Not true: you can be in a shell not in $PATH, and if you executed it from a relative path, which $0 will not find it if you cd to a different location.