I want to obtain the path of a Bash script, is when it’s executed through a symlink.
In this case, $0
is -bash
, while BASH_SOURCE
is the symlink’s path.
Can I obtain the script’s path through some shell variable, built-in shell command, or external command?
Will BASH_SOURCE
always holds the initial symlink’s path, even if the script is executed through several levels of indirection (multiple symlinks)?
Could I use ls
with BASH_SOURCE
to always retrieve the script’s path?