On Saturday 28 April 2007 10:31 pm, Ian Piumarta wrote:
Regardless, it's the caller that sets up argv[] for the child in execv*(). Bash empirically (read the source code) preserves precisely the command name typed by the user;
What you say is true - for binary executables. For scripts, see below.
it makes no attempt to
rewrite argv[0] to include dir information inferred from searching PATH....
For scripts, it does pathname expansion, opens the file to detect shebang interpreter and then passes the fullpath as $0 to the interp. Therefore, $0 in a shell script will contain the full pathname.
E.g.: # echo 'echo $0' >/bin/x.sh && x.sh /bin/x.sh # cat >/tmp/x.c <<EOF #include <stdio.h> #include <unistd.h> main(int argc, char *argv[]) { printf("arg0 is %s\n", argv[0]); execlp("x.sh", "x.sh", (char *)0); } EOF # cc -o /bin/x.tmp /tmp/x.c && x.tmp arg0 is x.tmp /bin/x.sh
Relocatable packages like autoconf and ghostscript (gs-common) have been using 'dirname $0' in their launcher scripts for a long time now, so the idiom is portable.
Coming back to my suggestions - we could simplify squeak vm by moving path logic into a launcher script. Invoked with the fullpath, the vm's plugin probe does not have to fail so many times before hitting the right location. Secondly, we could also unify the standalone launcher and plugin launcher.
Regards .. Subbu