3 ms·
In addition to other details noted about escaping/quoting and the portability of realpath, it's important to realize that those paths by default are not relativ
by jchw 3y ago
In addition to other details noted about escaping/quoting and the portability of realpath, it's important to realize that those paths by default are not relative to the invocation directory, they're relative to the current working directory, which happens to be the current working directory of the parent process initially. Also, for a shell script it is relatively reliable to rely on $0, but not guaranteed by any means: for example, an obvious way to subvert this would be to pipe the content of the script into a shell, though there's surely plenty of ways you can think of that this could be broken.