3 ms·
This isn't a portable solution at all because it doesn't solve the problem of the script being symlinked. While it does resolve directory symlilnks, that part i
by account42 3y ago
This isn't a portable solution at all because it doesn't solve the problem of the script being symlinked. While it does resolve directory symlilnks, that part is usually not even needed as finding a helper works just as well with a symlink to the directory containing the script as it does with the resolved directory. What doesn't work is a directory containing a symlink to the script which your "solution" fails to resolve.
Additionally (and the article doesn't solve this either), when invoked through $PATH, $0 will not be a full path but only the name of the command. In that case you want to start with "$(command -v "$0")" instead of just "$0".
- Asooka 3y agoNo, $0 is a full path when invoked via $PATH.