matz / zetabits.com (Yukihiro Matsumoto) writes: > |I guess there are two cases: > | > | 1. When the program is run using: > | > | ruby <path_to_rb> <options> > | > | Then you know the path, and all's well > | > | 2. When the program's run using a shebang line, then you may or may > | not get the path to the .rb file included. On Linux, this > | doesn't seem to be a problem. What's the status with other > | Unices? > > There's the third case. > > 3. When the program is run using execl(3) etc., where argv[0] and > the path to the executable might have no relation. > > And probably the fourth case to be considered. > > 4. the path to the executable is a symbolic link, so base path > should be resolved by following symbolic link. Oh, but I wasn't suggesting using argv[0] to pick up the name. Using /proc, neither of these is a problem under recent Linux, but might be under other Unices: $ cat t.c #include <unistd.h> int main() { int rc = execl("/tc/dave/tmp/link_to_ruby", "wombat", "-e", "p File.readlink('/proc/self/exe')", 0); perror("execl"); return rc; } $ make t $ ln -s /tc/usr/bin/ruby ~/tmp/link_to_ruby $ ./t "/tc/usr/bin/ruby" I'm not sure whether similar facilities to the /proc/self stuff exist on other boxes. Dave