#! and argv[0]: the path is removed before invoking the interpreter

From: Kevin Layer (layer@franz.com)
Date: Wed Feb 16 2000 - 13:49:35 EST


Consider this program, compiled into `foo':

        main(argc,argv,envp)
            char **argv;
            char **envp;
        {
            printf("argv[0] = %s\n", argv[0]);
            exit(0);
        }

and this script:

        #! /room3/layer/foo

On Solaris:

        ultra% ./foo.sh
        argv[0] = /room3/layer/foo

On 2.2.14 (Redhat 6.1):

        [layer@relay layer]$ ./foo.sh
        argv[0] = foo

I have an interpreter of #! scripts that absolutely needs to know the
full path of where the executable is, and I can't assume it will be in
the user's path. Getting it in argv[0] is the cleanest way. That is,
I can tell users they have to use the full path in the #!, if they
want to use my interpreter.

I believe the behavior of #! on Solaris goes all the way back to BSD
in of the early 80's. FreeBSD 3.0 behaves as Solaris does.

I hope this considered a bug. If there willingness to take a patch for
it, I might work on making the fix.

Kevin Layer layer@Franz.COM http://www.franz.com/
Franz Inc., 1995 University Avenue, Suite 275, Berkeley, CA 94704, USA
Phone: (510) 548-3600 FAX: (510) 548-8253

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:15 EST